你的位置:首页 > Java教程

[Java教程]CentOS6.5上编译OpenJDK7源码


本文地址:http://www.cnblogs.com/myresearch/p/build-openjdk7.html,转载请注明源地址。

采用开源的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-releaseCentOS release 6.5 (Final)[root@localhost ~]# uname -mx86_64[root@localhost ~]# uname -r2.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.repomv CentOS-Base.repo CentOS-Base.repo.bakmv CentOS6-Base-163.repo CentOS-Base.repoyum makecacheyum -y groupinstall 'base'yum -y install make

安装jdk必备软件包:

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

上传或下载相关文件到/application/tools

mkdir -p /application/toolscd /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.gzcd freetype-2.3.12./configure makemake install

安装JDK:

解压缩jdk-6u26-linux-i586.bin到application/java/目录下

设置环境变量如下:

#set java environmentJAVA_HOME=/application/java/jdkexport JRE_HOME=/application/java/jdk/jreexport CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATHexport 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 -versionjava 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 ~]# antBuildfile: build.!Build failed

3.配置变量

nset CLASSPATHunset JAVA_HOMEexport LANG=Cexport ALT_BOOTDIR=/application/java/jdkexport ANT_HOME=/application/tools/apache-ant-1.8.1/export ALT_FREETYPE_LIB_PATH=/usr/local/libexport SKIP_DEBUG_BUILD=falseexport SKIP_FASTDEBUG_BUILD=trueexport DEBUG_NAME=debugexport 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虚拟机》