在window10 WSL 中编译 OpenJDK13

简介

最新的OpenJDK13已经发布到git上,可以git pull,然后编译了。

这里介绍了直接在windows 10 的WSL环境中进行build并测试。

准备

在Open JDK13的网站文档中说,很简单的几步操作就好:

  1. 下载源码:
hg clone http://hg.openjdk.java.net/jdk/jdk

好吧,这一步可能会拦住很多的爱好者。要成功clone下来源码,很困难。

  1. 执行configure
    在源码的目录下,执行configure命令
bash configure
  1. 执行make
make images
  1. 验证得到的JDK
.build/*/images/jdk/bin/java -version

还可以执行test验证

make  run-test-tier1

开始

在第一步,要clone下来代码,在国内成功的可能性太低;
可以利用gitee码云来import在github上的openjdk的jdk13;然后再从gitee码云上clone到本地。
感谢码云gitee。

在github上的git 库访问地址,在gitee上import一下就OK了。

https://github.com/openjdk/jdk13

在第二步,在configure执行时,会检查很多的依赖项和命令。
在执行configure执行,还执行以下命令:

sudo apt-get install libfreetype6-dev libcups2-dev libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev libasound2-dev libffi-dev autoconf gcc clang libfontconfig1-dev

然后,还需要安装一下Boot-JDK; 安装boot-JDK: java-12-jdk.
Boot-JDK版本都是又要求的。一般要求是编译版本N-1,有些也可以N -2.
这里需要JDK12版本。

sudo apt-get install openjdk-12-jdk

现在,你可以开始执行 ./configure

错误

开始检查,可以缺少一下工具命令。比如zip、unzip……。

这个你可以轻松地安装搞定。

然后,出现boot-jdk错误 :

configure: Could not find a valid Boot JDK. OpenJDK distributions are available at http://jdk.java.net/.
configure: error: Cannot continue
configure: This might be fixed by explicitly setting --with-boot-jdk

这是什么?然后你可能按照提示, 使用命令参数 --with-boot-jdk指定安装好的JDK。

再执行 ./configure --with-boot-jdk=/usr/lib/jvm/java-12-openjdk-amd64/
继续失败。

checking for jni library path... default
checking if packaged modules are kept... yes (default)
checking for version string... 13-internal+0-adhoc.david.jdk13
configure: Found potential Boot JDK using configure arguments
configure: error: The path given by --with-boot-jdk does not contain a valid Boot JDK
configure: Potential Boot JDK found at /usr/lib/jvm/java-12-openjdk-amd64/ did not contain bin/java; ignoring

可boot-jdk就在那里!没办法,上午一番搜索。

在网上找到设置unset _JAVA_OPTIONS
继续失败。。

方法

没有折了。看一下building文档。里面针对window10 wsl,提到了需要特别注意的配置。

Windows Subsystem for Linux (WSL)

Windows 10 1809 or newer is supported due to a dependency on the wslpath utility and support for environment variable sharing through WSLENV. Version 1803 can work but intermittent build failures have been observed.

It's possible to build both Windows and Linux binaries from WSL. To build Windows binaries, you must use a Windows boot JDK (located in a Windows-accessible directory). To build Linux binaries, you must use a Linux boot JDK. The default behavior is to build for Windows. To build for Linux, pass --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu to configure.

按照说明,修改命令,再次执行新命令:

./configure --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu

然后就看到了结果成功完成。

执行命令:

config.status: creating /mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/Makefile

...
checking for which lcms to use... bundled
checking for cos in -lm... yes
checking for dlopen in -ldl... yes
checking if shenandoah can be built... yes
checking if zgc can be built... yes
checking if jvmci module jdk.internal.vm.ci should be built... yes
checking if graal module jdk.internal.vm.compiler should be built... yes
checking if aot should be enabled... yes
checking if cds should be enabled... yes
checking if elliptic curve crypto implementation is present... yes
checking if jtreg failure handler should be built... no, missing jtreg
checking if the CDS classlist generation should be enabled... yes
checking if any translations should be excluded... no
checking if static man pages should be copied... yes
checking if a default CDS archive should be generated... yes
checking for number of cores... 8
checking for memory size... 8098 MB
checking for appropriate number of jobs to run in parallel... 7
checking flags for boot jdk java command ...  -Duser.language=en -Duser.country=US  -XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=/mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/configure-support/classes.jsa -Xshare:auto
checking flags for boot jdk java command for big workloads...  -Xms64M -Xmx1600M -XX:ThreadStackSize=1536
checking flags for bootcycle boot jdk java command for big workloads... -Xms64M -Xmx1600M -XX:ThreadStackSize=1536
checking flags for boot jdk java command for small workloads...  -XX:+UseSerialGC -Xms32M -Xmx512M -XX:TieredStopAtLevel=1
checking whether to use sjavac... no
checking whether to use javac server... yes
checking If precompiled header is enabled... yes
checking that precompiled headers work... yes
checking is ccache enabled... no
checking if build directory is on local disk... no
checking JVM features for JVM variant 'server'... "aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc"
configure: creating /mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/configure-support/config.status
config.status: creating /mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/spec.gmk
config.status: creating /mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/bootcycle-spec.gmk
config.status: creating /mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/buildjdk-spec.gmk
config.status: creating /mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/compare.sh
config.status: creating /mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release/Makefile

====================================================
A new configuration has been successfully created in
/mnt/d/openjdk13/jdk13/build/linux-x86_64-server-release
using configure arguments '--build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu'.

Configuration summary:
* Debug level:    release
* HS debug level: product
* JVM variants:   server
* JVM features:   server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc'
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 13-internal+0-adhoc.david.jdk13 (13-internal)

Tools summary:
* Boot JDK:       openjdk version "12.0.2" 2019-07-16 OpenJDK Runtime Environment (build 12.0.2+9-Ubuntu-118.04) OpenJDK 64-Bit Server VM (build 12.0.2+9-Ubuntu-118.04, mixed mode)  (at /usr/lib/jvm/java-12-openjdk-amd64)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 7.4.0 (at /usr/bin/gcc)
* C++ Compiler:   Version 7.4.0 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   7
* Memory limit:   8098 MB

WARNING: Your build output directory is not on a local disk.
This will severely degrade build performance!
It is recommended that you create an output directory on a local disk,
and run the configure script again from that directory.

等待半小时后,build完成


Updating support/demos/image/jfc/Stylepad/src.zip
Compiling 5 files for BUILD_DEMO_SampleTree
Updating support/demos/image/jfc/SampleTree/src.zip
Compiling 8 files for BUILD_DEMO_TableExample
Updating support/demos/image/jfc/TableExample/src.zip
Note: /mnt/d/openjdk13/jdk13/src/demo/share/jfc/Metalworks/MetalworksPrefs.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Compiling 1 files for BUILD_DEMO_TransparentRuler
Updating support/demos/image/jfc/TransparentRuler/src.zip
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /mnt/d/openjdk13/jdk13/src/demo/share/jfc/TableExample/TableExample4.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /mnt/d/openjdk13/jdk13/src/demo/share/jfc/Stylepad/Stylepad.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Creating java.base.jmod
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Creating support/demos/image/jfc/CodePointIM/CodePointIM.jar
Creating support/demos/image/jfc/FileChooserDemo/FileChooserDemo.jar
Creating support/demos/image/jfc/Font2DTest/Font2DTest.jar
Creating support/demos/image/jfc/SwingSet2/SwingSet2.jar
Creating support/demos/image/jfc/J2Ddemo/J2Ddemo.jar
Creating support/demos/image/jfc/Metalworks/Metalworks.jar
Creating support/demos/image/jfc/Notepad/Notepad.jar
Creating support/demos/image/jfc/Stylepad/Stylepad.jar
Creating support/demos/image/jfc/SampleTree/SampleTree.jar
Creating support/demos/image/jfc/TableExample/TableExample.jar
Creating support/demos/image/jfc/TransparentRuler/TransparentRuler.jar
Creating jdk image
Creating CDS archive for jdk image
Stopping sjavac server
Finished building target 'images' in configuration 'linux-x86_64-server-release'

测试一下java command:

$ ./build/linux-x86_64-server-release/jdk/bin/java -version
openjdk version "13-internal" 2019-09-17
OpenJDK Runtime Environment (build 13-internal+0-adhoc.david.jdk13)
OpenJDK 64-Bit Server VM (build 13-internal+0-adhoc.david.jdk13, mixed mode)

检查javac command:

$ ./build/linux-x86_64-server-release/jdk/bin/javac -version
javac 13-internal

测试一下编译程序和执行

写一个hello

$ makedir samples
$ vi samples\hello.java

编写最简单的hello.java源码:

public class hello
{
   public static void main(String[] args) 
   {
      System.out.println("Hello, World ... ");
   }
}

编译执行:

$./build/linux-x86_64-server-release/jdk/bin/javac samples/hello.java -d .
$ ls hello.class
hello.class

$ ./build/linux-x86_64-server-release/jdk/bin/java hello
Hello, World...

以上,终于编译成功了。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值