標籤:
因為OpenJDK是開源的,這裡使用openJDK進行編譯聯絡
環境要求
- Centos6.7 64位
- openjdk-7u40-fcs-src-b43-26_aug_2013.zip
- bootstrap JDK: jdk1.6.0_38
因為我們是編譯,所以環境的話可以根據自己的實際情況進行調整,JDK的源碼包可以去這個網站進行下載https://jdk7.java.net/source.html
boostrap JDK:輔助JDK,意思是我們要編譯一個新的JDK時需要別的JDK來輔助完成,就像點火需要打火機一樣。
編譯前的準備
因為要進行編譯所以需要安裝相應的編譯工具
yum install -y gcc gcc-c++
yum install -y cups-devel
yum install -y alsa-lib-devel
yum install -y libXrender libXrender-devel libXi-devel libXt-devel libXtst-devel
yum install -y freetype freetype-devel
yum install -y java-1.6.0-openjdk java-1.6.0-openjdk-devel
yum install -y ant ant-nodeps
設定環境變數
編譯JDK時不同通過讀取設定檔來看使用者做了那些定製,而是用過讀取當前shell的環境變數來看設定的。在設定環境變數時可以參考以下指令碼
因為我們是要研究java虛擬機器的所以這裡開啟DEBUG模式
#!/bin/bash#clear settings if you have ever setup unset CLASSPAHTunset JAVA_HOME#select language, required export LANG=C#bootsrap JDK path installed, requiredexport ALT_BOOTDIR=/usr/local/jdk1.7.0_79#setup freetypeexport ALT_FREETYPE_LIB_PATH=/usr/local/libexport ALT_FREETYPE_HEADERS_PATH=/usr/local/include
#setup ant pathexport ANT_HOME=/root/apache-ant-1.9.7#dowload dependencies automaticallyexport ALLOW_DOWNLOADS=ture#setup number of compiled threads same to cpusexport HOTSPOT_BUILD_JOBS=1export ALT_PARALLEL_COMPILE_JOBS=1export SKIP_COMPARE_IMAGES=trueexport USE_PRECOMPILED_HEADER=true#setup what you want to compileexport BUILD_LANGTOOLS=true#export BUILD_JAXP=false#export BUILD_JAXWS=false#export BUILD_CORBA=falseexport BUILD_HOTSPOT=trueexport BUILD_JDK=true#setup arch=64 if your cpu is 64 or arch=32export ARCH_DATA_MODEL=64#setup version#export SKIP_DEBUG_BUILD=false#export SKIP_FASTDEBUG_BUILD=true#export DEBUG_NAME=debugBUILD_DEPLOY=false#cancel build install packageBUILD_INSTALL=false#setup output DIRexport ALT_OUTPUTDIR=/usr/local/jdk7-dev/build
注意:在執行指令碼時使用source命令執行 source setenv.sh
編譯環境檢查
當我們設定好環境變數後如果看我們的設定是否正確
進入源碼的根目錄,執行make sanity,如果結果如下則表示環境設定成功
編譯
在源碼的根目錄執行make all就可以進行編譯了
Centos下編譯JDK