0:官方文檔
http://hg.openjdk.java.net/jdk8/jdk8/raw-file/tip/README-builds.html
上面給出了編譯OpenJDK的官方文檔,可以自行閱讀一遍,了解詳情
1:環境準備
最好在linux、mac上面進行操作,相比windows會簡單很多
linux可以通過執行下面的指令得到系統版本資訊
lsb_release -a
下面是我linux的版本資訊我是centos的,官方是在ubuntu上面進行操作的,最好跟官方一緻,可以少踩一些坑
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
2:擷取源碼
執行下面的這指令
hg clone http://hg.openjdk.java.net/jdk8/jdk8 YourOpenJDK
如果出現下面的資訊,就表示還沒有安裝mercurial
[email protected]:/opt/open-compiler# hg clone http://hg.openjdk.java.net/jdk8/jdk8 YourOpenJDK
The program 'hg' is currently not installed. You can install it by typing:
apt-get install mercurial
執行下面的這行代碼安裝mercurial,如果沒有yum,自行安裝yum
yum install mercurial
安裝完成後,接着執行下面的這行代碼,擷取源碼
hg clone http://hg.openjdk.java.net/jdk8/jdk8 YourOpenJDK
如果出現下面的這些提示表示下載下傳完成(部分同學有可能出現英文形式的下面的這些提示嗎,也是一樣的)
正在請求全部修改
正在增加修改集
正在增加清單
正在增加檔案改變
已增加 942 個修改集,包含 1309 個改變,修改了 136 個檔案
updating to branch default
82 files updated, 0 files merged, 0 files removed, 0 files unresolved
如果出現下面的這行提示,表示下載下傳源碼的過程中出現了一些意外,重新執行下載下傳的那個指令,直到将源代碼下載下傳下來就好了
正在請求全部修改
正在增加修改集
正在增加清單
正在增加檔案改變
事務中止!
完成復原
中止: stream ended unexpectedly (got 9444 bytes, expected 24147)
3:确認編譯環境是否準備完全
執行下面的這行指令
bash ./configure
如果确認編譯環境的時候出現異常,那麼就安裝需要的環境資訊,例如出現下面的這個錯誤,這個就表示沒有unzip,那麼就安裝unzip
checking for unzip... no
configure: Could not find unzip!
configure: error: Cannot continue
configure exiting with result code 1
部分确實的環境他會提供安裝的指令,按照提示進行安裝就好了,例如下面的這個
checking for javac... no
checking for java... no
configure: Could not find a valid Boot JDK. You might be able to fix this by running 'sudo yum install java-1.7.0-openjdk'.
configure: This might be fixed by explicitely setting --with-boot-jdk
configure: error: Cannot continue
configure exiting with result code 1
但是按照他給的提示進行安裝之後,重新執行bash ./configure 指令之後又出現了下面的這個錯誤
checking for java... /usr/bin/java
configure: Found potential Boot JDK using well-known locations (in /usr/lib/jvm/jre-openjdk)
configure: Potential Boot JDK found at /usr/lib/jvm/jre-openjdk did not contain bin/javac; ignoring
configure: (This might be an JRE instead of an JDK)
configure: Found potential Boot JDK using well-known locations (in /usr/lib/jvm/jre-1.7.0-openjdk.x86_64)
configure: Potential Boot JDK found at /usr/lib/jvm/jre-1.7.0-openjdk.x86_64 did not contain bin/javac; ignoring
configure: (This might be an JRE instead of an JDK)
configure: Found potential Boot JDK using well-known locations (in /usr/lib/jvm/jre-1.7.0)
configure: Potential Boot JDK found at /usr/lib/jvm/jre-1.7.0 did not contain bin/javac; ignoring
configure: (This might be an JRE instead of an JDK)
configure: Found potential Boot JDK using well-known locations (in /usr/lib/jvm/jre)
configure: Potential Boot JDK found at /usr/lib/jvm/jre did not contain bin/javac; ignoring
configure: (This might be an JRE instead of an JDK)
configure: Found potential Boot JDK using well-known locations (in /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64)
configure: Potential Boot JDK found at /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64 did not contain bin/java; ignoring
configure: Could not find a valid Boot JDK. You might be able to fix this by running 'sudo yum install java-1.7.0-openjdk'.
configure: This might be fixed by explicitely setting --with-boot-jdk
configure: error: Cannot continue
configure exiting with result code 1
出現這個問題應該是你按照他安裝的隻是安裝了jre,而沒有安裝jdk(我猜的),然後我去網上找了下安裝openJdk的,就是執行下面的這個指令,執行完畢後再執行 bash ./configure指令就能夠通過jdk的這個環境了,安裝之後會在使用這個路徑下面的Boot JDK:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.201-2.6.16.1.el7_6.x86_64
yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel
但是又出現了一些其他的環境缺少,總之将這些缺失的環境都安裝起來就好了,下面是我遇到的一些其他的環境的确實,供參考
⑴:Could not find a C++ compiler
sudo yum groupinstall "Development Tools"
⑵:Could not find X11 libraries
sudo yum install libXtst-devel libXt-devel libXrender-devel
⑶:Could not find cups
sudo yum install cups-devel
⑷:Could not find freetype!
sudo yum install freetype-devel
⑸:Could not find alsa!
sudo yum install alsa-lib-devel
⑹:
Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You have ccache installed, but it is a version prior to 3.1.4. Try upgrading.
sudo yum install ccache
⑺:ccache status: installed, but disabled (version older than 3.1.4)
yum install ccache
基本都是在執行完bash ./configure之後,他會給你相應的提示,按照相應的提示進行操作就好了
4:開始編譯
執行下面的這個指令
make all
執行的時候出現下面的問題
Starting langtools
/bin/sh: 第 0 行? /root/YourOpenJDK/langtools/make: 沒有那個檔案或目錄
這個問題導緻的原因可能是你在最初執行bash ./get_source.sh指令的時候出現了中斷,然後部分的被復原了,這樣就不是最新的代碼,可以不斷的嘗試bash ./get_source.sh指令直到沒有出現異常復原的情況
上面這個問題解決後,接着執行make all指令,正常情況下會開始編譯了,最終出現下面的這個代碼提示的時候就是完成編譯了,編譯的時長會有點長(我的機子性能不好,編譯了快1個多鐘頭),慢慢等待編譯完成就好了
----- Build times -------
Start 2019-02-27 01:16:42
End 2019-02-27 01:20:41
00:00:00 corba
00:00:01 demos
00:03:22 docs
00:00:01 hotspot
00:00:33 images
00:00:00 jaxp
00:00:01 jaxws
00:00:01 jdk
00:00:00 langtools
00:00:00 nashorn
00:03:59 TOTAL
-------------------------
Finished building OpenJDK for target 'all'
在編譯完成後,編譯出來的jdk和jre在/root/YourOpenJDK/build/linux-x86_64-normal-server-release/images(你自己的YourOpenJDK路徑下面),然後可以進入images執行下面的指令
bin/java -version
就會出現下面的這個資訊,這樣基本就是說明你編譯成功了,至此編譯你的OpenJDK完成,恭喜
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-root_2019_02_26_11_34-b00)
OpenJDK 64-Bit Server VM (build 25.0-b70, mixed mode)