首先用書上的腳本嘗試,失敗。
之后根據源文件的 README 編譯,拋出:
root@linux:/opt/openjdk# sh ./get_source.sh ERROR: Need initial repository to use this script
采用下面的方案解決:
你jdk8版本太老了,但是你系統又比較新(很多工具,例如make也是最新的),導致很多不匹配。解決辦法換成最新版本的jdk8吧。 具體方法:hg clone http://hg.openjdk.java.net/jdk8u/jdk8u/ && sh get_source.sh. 后面就是一樣的。 -- by baidu 亂亂我不亂
需要注意,要使用 hg 必須先:
apt install mercurial
hg clone http://hg.openjdk.java.net/jdk9/jdk9 MyOpenJDK
cd MyOpenJDK
cat README
Welcome to OpenJDK! =================== For information about building OpenJDK, including how to fully retrieve all source code, please see either of these: * common/doc/building.html (html version) * common/doc/building.md (markdown version) See http://openjdk.java.net/ for more information about OpenJDK.
cd ./common/doc/
firefox building.html
cd /opt/MyOpenJDK/
sh get_source.sh
bash configure
checking for X11/extensions/shape.h... no configure: error: Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). You might be able to fix this by running 'sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev'. configure exiting with result code 1
apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev
bash configure
configure: error: Could not find cups! You might be able to fix this by running 'sudo apt-get install libcups2-dev'.
apt-get install libcups2-dev
在處理時有錯誤發生: oracle-java7-installer E: Sub-process /usr/bin/dpkg returned an error code (1)
bash configure
configure: error: Could not find freetype! You might be able to fix this by running 'sudo apt-get install libfreetype6-dev'.
apt-get install libfreetype6-dev
再次使用存在的到 download.oracle.com:80 的連接。 已發出 HTTP 請求,正在等待回應... 404 Not Found 2018-03-17 15:00:46 錯誤 404:Not Found。 download failed Oracle JDK 7 is NOT installed. dpkg: 處理軟件包 oracle-java7-installer (--configure)時出錯: 子進程 已安裝 post-installation 腳本 返回錯誤狀態 1 正在設置 libfreetype6:amd64 (2.6.1-0.1ubuntu2.3) ... 正在設置 zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4.1) ... 正在設置 libpng12-dev:amd64 (1.2.54-1ubuntu1) ... 正在設置 libfreetype6-dev:amd64 (2.6.1-0.1ubuntu2.3) ... 正在處理用於 libc-bin (2.23-0ubuntu5) 的觸發器 ... 在處理時有錯誤發生: oracle-java7-installer E: Sub-process /usr/bin/dpkg returned an error code (1)
# 1. oracle openjdk ppa source sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-7-jdk // OpenJdk 7安裝:
update-alternatives --config javac
update-alternatives --config java
改成 openJDK 7
再次 bash configure
==================================================== A new configuration has been successfully created in /opt/MyOpenJDK/build/linux-x86_64-normal-server-release using default settings. Configuration summary: * Debug level: release * HS debug level: product * JDK variant: normal * JVM variants: server * OpenJDK target: OS: linux, CPU architecture: x86, address length: 64 * Version string: 9-internal+0-adhoc.root.MyOpenJDK (9-internal) Tools summary: * Boot JDK: openjdk version "1.8.0_151" OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12) OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode) (at /usr/lib/jvm/java-8-openjdk-amd64) * Toolchain: gcc (GNU Compiler Collection) * C Compiler: Version 5.4.0 (at /usr/bin/gcc) * C++ Compiler: Version 5.4.0 (at /usr/bin/g++) Build performance summary: * Cores to use: 3 * Memory limit: 3840 MB
於是我 make images
root@linux:/opt/MyOpenJDK# make images Building target 'images' in configuration 'linux-x86_64-normal-server-release' /bin/bash: 第 0 行: cd: /opt/MyOpenJDK/hotspot/make: 沒有那個文件或目錄 make[2]: *** [hotspot-server-gensrc] Error 1 make[2]: *** 正在等待未完成的任務.... make/Main.gmk:255: recipe for target 'hotspot-server-gensrc' failed Compiling 8 files for BUILD_TOOLS_LANGTOOLS ERROR: Build failed for target 'images' in configuration 'linux-x86_64-normal-server-release' (exit code 2) === Make failed targets repeated here === make/Main.gmk:255: recipe for target 'hotspot-server-gensrc' failed === End of repeated output === Hint: Try searching the build log for the name of the first failed target. Hint: See common/doc/building.html#troubleshooting for assistance. /opt/MyOpenJDK/make/Init.gmk:291: recipe for target 'main' failed make[1]: *** [main] Error 1 /opt/MyOpenJDK/make/Init.gmk:185: recipe for target 'images' failed make: *** [images] Error 2
(失敗)
再嘗試 bash configure
WARNING: The result of this configuration has overridden an older configuration. You *should* run 'make clean' to make sure you get a proper build. Failure to do so might result in strange build problems.
x
我記得 opne jdk8u 目錄下是有hotspot 的,但是jdk9 目錄下找不到。正好沒有把open jdk8u刪掉,切進去試試。
/opt/jdk8u# bash configure
通過配置檢查,並得到下面的提示:
Build performance tip: ccache gives a tremendous speedup for C++ recompilations. You do not have ccache installed. Try installing it. You might be able to fix this by running 'sudo apt-get install ccache'.
apt-get install ccache(失敗)
make images
警告: [options] 未與 -source 1.6 一起設置引導類路徑 1 個警告 Generating linux_amd64_docs/jvmti.html INFO: ENABLE_FULL_DEBUG_SYMBOLS=1 INFO: ALT_OBJCOPY=/usr/bin/objcopy INFO: /usr/bin/objcopy cmd found so will create .debuginfo files. INFO: STRIP_POLICY=min_strip INFO: ZIP_DEBUGINFO_FILES=1 ## Finished hotspot (build time 00:04:56) ## Starting corba /bin/sh: 1: cd: can't cd to /opt/jdk8u/corba/make /opt/jdk8u//make/Main.gmk:89: recipe for target 'corba-only' failed make: *** [corba-only] Error 2
貌似是編譯了一半。
再試一次 make all
root@linux:/opt/jdk8u# make all Building OpenJDK for target 'all' in configuration 'linux-x86_64-normal-server-release' ## Starting langtools ## Finished langtools (build time 00:00:01) ## Starting hotspot ## Finished hotspot (build time 00:00:00) ## Starting corba /bin/sh: 1: cd: can't cd to /opt/jdk8u/corba/make /opt/jdk8u//make/Main.gmk:89: recipe for target 'corba-only' failed make: *** [corba-only] Error 2
重頭再來一遍,不行就用 vps 試一試。
hg clone http://hg.openjdk.java.net/jdk9/jdk9 cd jdk9 bash get_source.sh bash configure make images ./build/*/images/jdk/bin/java -version make run-test-tier1
還是失敗了,get_source.sh 的時候報了很多類似這樣的:
abort: stream ended unexpectedly (got 115 bytes, expected 245)
還是一樣的命令,換 vps :
get_source.sh
WARNING: jaxws exited abnormally (255) root@xkfx:/opt/jdk9# hg clone http://hg.openjdk.java.net/jdk9/jdk9/jaxws jaxws
openjdk
—— corba:不流行的多語言、分布式通訊接口
—— hotspot:Java 虛擬機
—— jaxp:XML 處理
—— jaxws:一組 XML web services 的 Java API
—— jdk:java 開發工具包
—— —— 針對操作系統的部分
—— —— share:與平台無關的實現
—— langtools:Java 語言工具
—— nashorn:JVM 上的 JavaScript 運行時
來自 只會一點java
get_source 成功的話,目錄應該是這樣的
root@xkfx:/opt/jdk9# ls ASSEMBLY_EXCEPTION corba jaxp langtools Makefile test common get_source.sh jaxws LICENSE nashorn configure hotspot jdk make README
bash configure
configure: error: Could not find required tool for ZIPEXE configure exiting with result code 1
apt-get install zip
bash configure
make clean
make images
然后掛在后台編譯,
root@xkfx:/opt/jdk9/build/linux-x86_64-normal-server-release/images/jdk/bin# ./java -version openjdk version "9-internal" OpenJDK Runtime Environment (build 9-internal+0-adhoc.root.jdk9) OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.root.jdk9, mixed mode)
查看主要源代碼:
sudo apt-get install tree
tree 以樹狀圖顯示所有文件
tree -L N 以樹狀圖顯示所有文件,子文件夾顯示到第 N 層
root@xkfx:/opt/jdk9/hotspot/src# tree -L 1
.
├── cpu
├── jdk.aot
├── jdk.hotspot.agent
├── jdk.internal.vm.ci
├── jdk.internal.vm.compiler
├── os
├── os_cpu
└── share