首頁 > 軟體

CentOS 6.5上編譯安裝OpenJDK7原始碼

2020-06-16 18:00:38

採用開源的OpenJDK版本,獲取其原始碼的方式有兩種:

  • 通Mercurial程式碼版本管理工具從Repository中直接取得原始碼,但是速度太慢,需要花費數小時

  • 直接下載官方打包好的原始碼包(推薦)

下載原始碼openjdk-7u6-fcs-src-b24-28_aug_2012.zip,解壓,下載地址如下:

http://www.java.net/download/openjdk/jdk7u6/promoted/b24/openjdk-7u6-fcs-src-b24-28_aug_2012.zip

本次編譯採用的是64位元的OS,編譯也是64位元的JDK,記憶體至少需要512MB

1.基本流程

(閱讀README和README-builds.html)

README-builds.html中包含有詳細的安裝資訊,最好能完整的閱讀一下。

2.安裝基礎軟體包

我的CentOS6.5安裝在vmware10上,安裝時使用最小化(Minimal)安裝

[root@localhost ~]# cat /etc/RedHat-release
CentOS release 6.5 (Final)
[root@localhost ~]# uname -m
x86_64
[root@localhost ~]# uname -r
2.6.32-431.el6.x86_64

設定更新源

cd /etc/yum.repos.d/
curl http://mirrors.163.com/.help/CentOS6-Base-163.repo > CentOS6-Base-163.repo 

當前wget還不能用

#wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
mv CentOS-Base.repo CentOS-Base.repo.bak
mv CentOS6-Base-163.repo CentOS-Base.repo
yum makecache

yum -y groupinstall 'base'
yum -y install make

安裝jdk必備軟體包:

yum -y install alsa-lib-devel
yum -y install cups-devel
yum -y install libXi-devel
yum -y install gcc gcc-c++
yum -y install libX*

上傳或下載相關檔案到/application/tools

mkdir -p /application/tools
cd /application/tools

上傳或下載下列相關檔案到/application/tools

freetype-2.3.12.tar.gz  下載地址:http://sourceforge.net/projects/freetype/files/freetype2/

openjdk-7u6-fcs-src-b24-28_aug_2012.zip  下載地址前文

apache-ant-1.7.1-bin.zip  下載地址:http://archive.apache.org/dist/ant/binaries/  

jdk-6u26-linux-x64.bin  下載地址:http://www.Oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jdk-6u26-oth-JPR

編譯安裝freetype:

tar -xzf freetype-2.3.12.tar.gz
cd freetype-2.3.12
./configure 
make
make install

安裝JDK:

解壓縮jdk-6u26-linux-i586.bin到application/java/目錄下

設定環境變數如下:

#set java environment
JAVA_HOME=/application/java/jdk
export JRE_HOME=/application/java/jdk/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

安裝ant:

cd /application/tools/
unzip apache-ant-1.7.1-bin.zip 
ln -s /application/tools/apache-ant-1.7.1/bin/ant /usr/bin/ant

檢查java與ant:

[root@localhost ~]# java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
[root@localhost ~]# ant
Buildfile: build.xml does not exist!
Build failed

3.設定變數

nset CLASSPATH
unset JAVA_HOME
export LANG=C
export ALT_BOOTDIR=/application/java/jdk
export ANT_HOME=/application/tools/apache-ant-1.8.1/
export ALT_FREETYPE_LIB_PATH=/usr/local/lib
export SKIP_DEBUG_BUILD=false
export SKIP_FASTDEBUG_BUILD=true
export DEBUG_NAME=debug
export ALT_FREETYPE_HEADERS_PATH=/usr/local/include/freetype2

4.檢查環境是否設定OK與編譯jdk原始碼

[root@localhost tools]# cd openjdk
[root@localhost openjdk]# pwd
/application/tools/openjdk
[root@localhost openjdk]# make sanity

……

OpenJDK-specific settings:
FREETYPE_HEADERS_PATH = /usr/local/include/freetype2
ALT_FREETYPE_HEADERS_PATH = /usr/local/include/freetype2
FREETYPE_LIB_PATH = /usr/local/lib
ALT_FREETYPE_LIB_PATH = /usr/local/lib

Previous JDK Settings:
PREVIOUS_RELEASE_PATH = USING-PREVIOUS_RELEASE_IMAGE
ALT_PREVIOUS_RELEASE_PATH =
PREVIOUS_JDK_VERSION = 1.6.0
ALT_PREVIOUS_JDK_VERSION =
PREVIOUS_JDK_FILE =
ALT_PREVIOUS_JDK_FILE =
PREVIOUS_JRE_FILE =
ALT_PREVIOUS_JRE_FILE =
PREVIOUS_RELEASE_IMAGE = /application/java/jdk
ALT_PREVIOUS_RELEASE_IMAGE =


Sanity check passed.

執行下列命令:

[root@localhost openjdk]# make all

Build times ----------
Target debug_build
Start 2015-05-05 09:34:37
End 2015-05-05 10:24:33
00:05:23 corba
00:10:49 hotspot
00:00:55 jaxp
00:01:07 jaxws
00:30:05 jdk
00:01:36 langtools
00:49:56 TOTAL
-------------------------
make[1]: Leaving directory `/application/tools/openjdk'

檢視成果:

[root@localhost openjdk]#  ./build/linux-amd64/bin/java -version

openjdk version "1.7.0-internal-debug"
OpenJDK Runtime Environment (build 1.7.0-internal-debug-root_2015_05_05_09_15-b00)
OpenJDK 64-Bit Server VM (build 23.2-b09-jvmg, mixed mode)

參考資料

《深入Java虛擬機器》

深入Java虛擬機器(原書第2版) PDF【中文版+附光碟原始碼】  下載地址: http://www.linuxidc.com/Linux/2013-06/86222.htm

RHEL6.5安裝OpenJDK1.7.0 + JBoss7.1.1 + Maven3.0.4 http://www.linuxidc.com/Linux/2014-04/99854.htm

Fedora 20下安裝官方JDK替換OpenJDK並設定環境變數 http://www.linuxidc.com/Linux/2014-03/97523.htm

Ubuntu OpenJDK + Tomcat7 的安裝 http://www.linuxidc.com/Linux/2014-02/96398.htm

Ubuntu 13.04下升級到Maven3.10 以支援 OpenJDK7 http://www.linuxidc.com/Linux/2013-08/88844.htm

Ubuntu 12.10中編譯安裝OpenJDK 7 http://www.linuxidc.com/Linux/2013-03/81948.htm

本文永久更新連結地址http://www.linuxidc.com/Linux/2015-05/117248.htm


IT145.com E-mail:sddin#qq.com