在window10 WSL 中编译 OpenJDK13
簡介
最新的OpenJDK13已經發布到git上,可以git pull,然后編譯了。
這里介紹了直接在windows 10 的WSL環境中進行build并測試。
準備
在Open JDK13的網站文檔中說,很簡單的幾步操作就好:
好吧,這一步可能會攔住很多的愛好者。要成功clone下來源碼,很困難。
在源碼的目錄下,執行configure命令
還可以執行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執行,還執行以下命令:
然后,還需要安裝一下Boot-JDK; 安裝boot-JDK: java-12-jdk.
Boot-JDK版本都是又要求的。一般要求是編譯版本N-1,有些也可以N -2.
這里需要JDK12版本。
現在,你可以開始執行 ./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/
繼續失敗。
可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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 别人裁员我扩招!2022年特斯拉新增2.
- 下一篇: “空中女王”正式谢幕 波音747即日交付