简介

最新的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 MBWARNING: 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...

以上,终于编译成功了。

在window10 WSL 中编译 OpenJDK13相关推荐

  1. 在Win10 WSL中安装百度Apollo

    在Win10 WSL中安装百度Apollo 前言 说明 安装WSL及Ubuntu发行版 配置WSL 1^11 安装 Docker 安装Apollo 局域网其他设备接入Dreamview4^44 前言 ...

  2. WSL中的ubuntu安装最新的Cmake及其使用(win11)

    1.先从官网上下载最新的cmake安装包 cmake package 2. 对下载的软件进行sha256值的比较 ➜ ~ sha256sum cmake-3.21.2-linux-x86_64.tar ...

  3. Geant4在Ubuntu(WSL)中,安装过程详解,附Geant4一键安装脚本

    背景(撰写本攻略的缘由) 本文是 Geant4 及ROOT 在windows子系统(WSL)中的快速安装 的姊妹篇.上文应该是全网第一篇中文的在WSL中安装Geant4的教程. 当时笔者还很年轻,对L ...

  4. 【Qt】在QtCreator中编译log4cplus

    在QtCreator中编译log4cplus 一.在QtCreator中配置cmake 二.编译log4cplus 1.下载 2.编译.安装 一.在QtCreator中配置cmake 参见博客:htt ...

  5. 关于使用JAVA中JDK安装和在命令行中编译和运行程序的一些总结

    JDK安装:http://www.oracle.com/technetwork/java(可以选择安装路径) (在写下载这个JDK时需要先创建账户) 1.下载完之后就可以安装了,安装路径自己可以设置, ...

  6. [转载]在Eclipse CDT中编译含有多个main函数的项目

    在Eclipse CDT中编译含有多个main函数的项目 在C/C++项目中有时候会需要在一个项目中包含多个main函数.在Visual Studio中,这种情况可以由一个解决方案下带多个项目来解决, ...

  7. 关于ios中编译ffmpeg0.9.2库

    很多朋友在问如何在ios中编译ffmpeg库,虽说网上的教程很多,但是大部分都说按其操作,最后编译总是不成功,正好我最近的项目要用到ffmpeg,所以就再次编译了,同时在这里记下,方便需要参考的朋友. ...

  8. list在codeblocks和vs2013中编译提示不同

    代码如下: #include <iostream> #include <list>using namespace std;int main(void) {list<int ...

  9. Visual studio中编译和使用libpng和zlib

    Visual studio中编译和使用libpng和zlib https://blog.csdn.net/jinzhuojun/article/details/7972747 转载于:https:// ...

最新文章

  1. go get 失败 no go files in_Go 每日一库之 dig
  2. 师范类专业可以不考计算机二级吗,2021师范专业要考教师资格证吗?师范生需要考的证有哪些?...
  3. nodejs async
  4. 答辩攻略之二:纯方案赛
  5. mediawiki java_使用MediaWiki 1.16.0实现添加媒体向导
  6. 如何写 go 代码 (How to Write Go Code 翻译)
  7. mysql会对同时读取加锁吗_程序员经典面试题,MySQL并发读写的时候,都是需要加锁的么?...
  8. 代码测试意味着完全消灭了 Bug?
  9. java判断是否能上网_用Java检测远程主机是否能被连接
  10. Linux 简单的双线设置
  11. 10个优质的Java练手项目
  12. RabbitMQ An unexpected connection driver error occured错误
  13. 一般网站建设大概需要多少钱?
  14. 数据挖掘课程第一章作业《认识数据挖掘与数据预处理》
  15. 期货开户手续费的收取方式是什么?
  16. 太妙了!几个用Python给图片添加水印的方法,简单实用!
  17. Jetty in Win7
  18. Flex布局做出自适应页面--语法和案例
  19. Android Studio 批量修改文件名
  20. C语言 深度剖析数据在内存中的存储

热门文章

  1. Linux之加密和安全
  2. 尚洋优选健康美电商平台启动仪式在广州召开
  3. 中国人工智能学会通讯——神经环路研究最新进展及对类脑计算的启示 1.复杂科学...
  4. 转: 七牛云的开源播放器的使用指南
  5. CentOS7下PHPNginxMysql编译安装及sytemd配置
  6. UIView使用UIMotionEffect效果
  7. jquery插件之thickbox
  8. mysql分表那些事儿
  9. oracle nowday,Java MonthDay now()用法及代码示例
  10. php 如何获取表格数据类型,使用phpword获取doc中的表格数据