采用开源的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)