CentOS下編譯安裝OpenJDK6過程

來源:互聯網
上載者:User

CentOS下編譯安裝OpenJDK6過程

由於初次手動編譯OpenJDK6, 踩的坑還不少, 各種依賴不足以及奇葩的事情, 特此整理記錄, 給後人防坑.
編譯環境資訊:

[root@dev-52 ~]# uname -aLinux dev-52 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux[root@dev-52 openjdk6]# arch && cat /etc/centos-release x86_64CentOS release 6.2 (Final)[root@dev-52 openjdk6]# nproc 8[root@dev-52 ~]# free -m             total       used       free     shared    buffers     cachedMem:          7872       7695        176          0        158       6794-/+ buffers/cache:        742       7129Swap:         5823          0       5823

OpenJDK版本:openjdk-6-src-b27-26_oct_2012.tar.gz :https://java.net/projects/openjdk6/downloads/

[root@dev-52 ~]# mkdir openjdk6 && tar xf openjdk-6-src-b27-26_oct_2012.tar.gz -C openjdk6[root@dev-52 ~]# ll openjdk6總計 320-rw-rw-r-- 1 uucp 143   1503 2012-10-27 02:21 ASSEMBLY_EXCEPTIONdrwxrwxr-x 4 uucp 143   4096 2012-10-27 02:28 corba-rw-rw-r-- 1 uucp 143   1373 2012-10-27 02:21 get_source.shdrwxrwxr-x 6 uucp 143   4096 2012-10-27 02:28 hotspotdrwxrwxr-x 5 uucp 143   4096 2012-10-27 02:28 jaxpdrwxrwxr-x 5 uucp 143   4096 2012-10-27 02:28 jaxwsdrwxrwxr-x 5 uucp 143   4096 2012-10-27 02:28 jdkdrwxrwxr-x 5 uucp 143   4096 2012-10-27 02:29 langtools-rw-rw-r-- 1 uucp 143  19263 2012-10-27 02:21 LICENSEdrwxrwxr-x 4 uucp 143   4096 2012-10-27 02:28 make-rw-rw-r-- 1 uucp 143  14485 2012-10-27 02:21 Makefile-rw-rw-r-- 1 uucp 143   1803 2012-10-27 02:21 README-rw-rw-r-- 1 uucp 143 101427 2012-10-27 02:21 README-builds.html-rw-rw-r-- 1 uucp 143   4807 2012-10-27 02:21 ReleaseProcess.htmldrwxrwxr-x 2 uucp 143   4096 2012-10-27 02:28 test-rw-rw-r-- 1 uucp 143 127498 2012-10-27 02:21 THIRD_PARTY_README-rw-rw-r-- 1 uucp 143   2113 2012-10-27 02:21 TRADEMARK# 安裝依賴, 編譯OpenJDK需要先安裝一個JDK, 無論是OpenJDK還是Oracle JDK都行[root@dev-52 ~]# yum install java-1.6.0-openjdk alsa-lib-devel gawk binutils libpng-devel freetype-devel openmotif openmotif-devel cups-devel ant libXtst-devel -y# 將編譯參數全部寫到一個指令碼中[root@dev-52 openjdk6]# cd openjdk6[root@dev-52 openjdk6]# vim build.sh #!/bin/bashexport OPENJDK_HOME=/root/openjdk6 # 解壓的源碼包位置export LANG=Cexport ALT_BOOTDIR=/usr/lib/jvm/java-1.6.0-openjdk.x86_64 # 機器上現有的JDK位置, 下面一樣export ALT_JDK_IMPORT_PATH=/usr/lib/jvm/java-1.6.0-openjdk.x86_64export ALT_OUTPUTDIR=$OPENJDK_HOME/build # 編譯輸出目錄export ALLOW_DOWNLOADS=trueexport HOTSPOT_BUILD_JOBS=8 # 編譯線程數, 與CPU核心數一致即可export ALT_PARALLEL_COMPILE_JOBS=8export DEV_ONLY=trueexport USE_PRECOMPILED_HEADER=trueexport BUILD_LANGTOOLS=trueexport BUILD_JAXP=false # 下面三個組件編譯時間需要從網路上下載相關依賴包, 耗時較長且對於作者沒有任何用處就取消編譯了export BUILD_JAXWS=falseexport BUILD_CORBA=falseexport BUILD_HOTSPOT=trueexport BUILD_JDK=trueexport BUILD_DEPLOY=false # 取消構建部署和安裝包export BUILD_INSTALL=falseunset JAVA_HOMEunset CLASSPATHmake sanity # 驗證[root@dev-52 openjdk6]# chmod +x build.sh [root@dev-52 openjdk6]# ./build.sh # 由於輸出內容過長佔用篇幅較大就不完全貼出來了, 尾部的輸出如下:WARNING: You are not building the JAXP sources.         The jaxp files will be obtained from          the location set in ALT_JDK_IMPORT_PATH. WARNING: You are not building the JAXWS sources.         The jaxws files will be obtained from          the location set in ALT_JDK_IMPORT_PATH. WARNING: You are not building the CORBA sources.         The corba files will be obtained from          the location set in ALT_JDK_IMPORT_PATH. WARNING: Your build environment has the variable DEV_ONLY         defined. This will result in a development-only         build of the JDK, lacking the documentation         build and installation bundles.Sanity check passed. # 檢查通過# 修改build.sh的最後一行為如下, 然後在此執行指令碼: make sanity && make 2>&1 | tee $ALT_OUTPUTDIR/build.log[root@dev-52 openjdk6]# ./build.sh # 自2015年開始一般會出現如下異常/opt/jdk1.6.0_31/bin/java  -Xmx896m -Xms128m -XX:PermSize=32m -XX:MaxPermSize=160m -jar /root/openjdk6/build/btjars/generatecurrencydata.jar -o /root/openjdk6/build/lib/currency.data.temp \                < ../../../src/share/classes/java/util/CurrencyData.propertiesError: time is more than 10 years from present: 1120165200000java.lang.RuntimeException: time is more than 10 years from present: 1120165200000        at build.tools.generatecurrencydata.GenerateCurrencyData.makeSpecialCaseEntry(GenerateCurrencyData.java:285)        at build.tools.generatecurrencydata.GenerateCurrencyData.buildMainAndSpecialCaseTables(GenerateCurrencyData.java:225)        at build.tools.generatecurrencydata.GenerateCurrencyData.main(GenerateCurrencyData.java:154)make[4]: *** [/root/openjdk6/build/lib/currency.data] Error 1# 通過修改CurrencyData.properties檔案, 把10年之前的時間修改為10年之內即可# 部分amd64架構的機器可能會出現如下異常cd linux_amd64_compiler2/product && ./test_gammajava full version "1.6.0_36-b36"./gamma: relocation error: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.36.x86_64/jre/lib/amd64/libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference# 主要是由於OpenJDK的一個bug導致的, 把OpenJDK替換為Oracle JDK即可, 注意同時修改build.sh中的內容[root@dev-52 openjdk6]# vim `find . -name 'CurrencyData.properties'`# 編譯完成後末尾輸出如下, 也可檢查程式的退出碼:>>>Making sec-files-win @ Mon Sep  7 15:06:20 CST 2015 ...>>>Making jgss-files @ Mon Sep  7 15:06:20 CST 2015 ...>>>Finished making images @ Mon Sep  7 15:06:20 CST 2015 ...make[2]: Leaving directory `/root/openjdk6/jdk/make'make[1]: Leaving directory `/root/openjdk6'Control linux amd64 1.6.0-internal build_product_image build finished: 15-09-07 15:06Control linux amd64 1.6.0-internal all_product_build build finished: 15-09-07 15:06Control linux amd64 1.6.0-internal all build finished: 15-09-07 15:06[root@dev-52 openjdk6]# echo $?0# 退出碼為0說明程式正常退出, 編譯成功進入輸出目錄的j2sdk-image下, 即可看到編譯好的JDK了[root@dev-52 openjdk6]# cd build/j2sdk-image/bin[root@dev-52 j2sdk-image]# lsASSEMBLY_EXCEPTION  bin  demo  include  jre  lib  LICENSE  man  sample  src.zip  THIRD_PARTY_README[root@dev-52 bin]# ./java -versionopenjdk version "1.6.0-internal"OpenJDK Runtime Environment (build 1.6.0-internal-root_07_sep_2015_14_49-b00)OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

到此整個編譯過程就結束了, 當然第一次編譯肯定不會這麼順利的完成, 操作時需要細心, 當然編譯OpenJDK7也是大同小異, 在debain平台下依賴包的名字可能會有差異, 這需要注意一下. OK, 對JVM感興趣的同學趕緊親自動手試一下吧.

參考資料
  • 《深入理解Java虛擬機器:JVM進階特性與最佳實務》 作者: 周志明
  • http://blog.csdn.net/bysun2013/article/details/41984335
  • http://openjdk.java.net/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.