Windows10编译OpenJDK8
前言
本文基于win10(64位)编译openjdk8,碰到各种问题被卡住,最终还好编译完成,总结如下,希望对你有帮助
1. 环境准备
- Windows 10
- oracleJDK8
- 官方下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- 选择windows x64下载
- 需要登录,可以查看这篇:https://blog.csdn.net/Virgil_K2017/article/details/90260880
- Openjdk8源码
- Cygwin
- 官方下载链接:http://www.cygwin.com/setup-x86_64.exe
- 安装帮助博客:https://blog.csdn.net/u010356768/article/details/90756742
- 推荐一个工具apt-cyg,在安装cygwin时,一定要先安装wget. 然后从github上下载https://github.com/transcode-open/apt-cyg,放在cygwin的/usr/local/bin目录下,
chmod +x apt-cyg
加上可执行权限,然后可以通过apt-cyg install 下载我们需要的包
- freetype
- 官方源码下载链接:https://sourceforge.net/projects/freetype/files/freetype2/2.8.1/freetype-2.8.1.tar.gz/download
- dll、lib文件:https://github.com/ubawurinna/freetype-windows-binaries
- 可以自己从源码编译,也可以直接使用已经编译好的文件
- VS2010
2. 软件安装重点
- 将vs2010安装目录下VC\bin 加入PATH中
- 根据README-builds.md ,cygwin需要安装以下工具
- ar
- make
- m4
- cpio
- gawk
- file
- zip
- unzip
- free
3. configure
将–with-freetype的目录指向编译好的freetype目录,以下是我的configure执行命令,如果没有配置oracle java环境变量,需要配置--with-boot-jdk
./configure --with-freetype=/cygdrive/c/Users/supre/Desktop/openjdk8/openjdk-8/freetype --with-target-bits=64 --enable-debug
报错
-
–with-freetype配置不对报错,最好使用绝对路径
configure: error: Can not find or use freetype at location given by --with-freetype
-
Your cygwin is too old
configure: Your cygwin is too old. You are running 2.11.1(0.329/5/3), but at least cygwin 1.7 is required. Please upgrade.
解决方法:common\autoconf\generated-configure.sh搜索Your cygwin is too old,将第7220行的1.7修改为自己cygwin版本号,我的就是修改为2.11
-
Target CPU mismatch,中文版vs造成的
configure: error: Target CPU mismatch. We are building for x86_64 but CL is for""; expected "x64"
解决方法:common\autoconf\generated-configure.sh 查找Target CPU mismatch. We are building, 将相关代码注释, 20043-20051行和21622-21630行注释掉
4. make
在configure完成的目录下执行make命令
make
报错
-
fatal error U1073: 不知道如何生成xinclude.mod
NMAKE : fatal error U1073: 不知道如何生成“C:\Users\supre\Desktop\openjdk8\openjdk-8\hotspot/src/share/vm/trace/xinclude.mod” Stop. NMAKE : fatal error U1077: “cd”: 返回代码“0x2” Stop. NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\nmake.EXE"”: 返回代码“0x2”
解决方法:这个报错在网上没有找到类似的解决方法,后来发现是我下的这个openjdk源码少了xinclude.mod这个文件,重新从官网下了一个放在给定的目录就OK了
-
integer expressionexpected错误
## Starting hotspot make[2]: warning: -jN forced in submake: disabling jobserver mode. INFO: ENABLE_FULL_DEBUG_SYMBOLS=1 C:\Users\supre\Desktop\openjdk8\openjdk-8\hotspot/make/windows/get_msc_ver.sh: line 65: [: 用于 x64 的 Microsoft (R) C/C++ 优化编译器 16: integer expressionexpected /usr/bin/expr: syntax error NMAKE : fatal error U1077: “sh”: 返回代码“0x2”
解决方法:在hotspot\make\windows\get_msc_ver.sh 将65-70注释,改为
MSC_VER_RAW=16.00.303109.01 MSC_VER=1600
具体版本,可以根据cl.exe执行得到版本信息,这个是因为中文版vs输出中文信息,脚本是根据英文版写的,不能得到版本信息,我的vs cl版本如下
用于 x64 的 Microsoft (R) C/C++ 优化编译器 16.00.30319.01 版
5.make install
make完成后,需要执行make install 将生成的文件集中在某个目录,没有指定默认放在/usr/local/jvm下
make install
-
Exception in thread “main” java.lang.VerifyError: class
Running nasgen Exception in thread "main" java.lang.VerifyError: class jdk.nashorn.internal.objects.ScriptFunctionImpl overrides final method setPrototype.(Ljava/lang/Object;)
解决方法: nashorn/make/BuildNashorn.gmk 80行原来 -cp 修改为:-Xbootclasspath/p:
-
error CreateJars.gmk:268
make[2]: *** [CreateJars.gmk:268: /cygdrive/c/Users/supre/Desktop/openjdk8/openjdk-8-master/build/windows-x86_64-normal-server-release/images/lib/_the.rt.jar.contents] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [BuildJdk.gmk:101: images] Error 2 make: *** [/cygdrive/c/Users/supre/Desktop/openjdk8/openjdk-8-master//make/Main.gmk:136: images-only] Error7 2
解决方法:
- 用vi打开jdk/make目录下的CreateJars.gmk
- 按esc 进入命令模式, 输入268gg回车定位到268行,相距不远处有两个$$换行符,将其转换为Windows下的换行符。
- 将光标定位到两个$$之前,按i切换到insert模式后,按Ctrl + V, Ctrl + M,即可打出^M
- 完成后按esc退出编辑模式,然后按:进入命令模式,输入wq保存并退出
- make clean, 重新make
完成
在/usr/local/jvm就有生成的openjdk-1.8.0-internal文件夹,执行java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-supre_2019_12_19_22_37-b00)
OpenJDK 64-Bit Server VM (build 25.0-b70, mixed mode)
参考
来源:CSDN
作者:aabond
链接:https://blog.csdn.net/qq_23091073/article/details/103656914