1、<<深入理解Java虚拟机--JVM高级特性与最佳实践>>第一章谈到自己编译jdk,所以今天尝试在CentOS6.5上编译openJDK7。
2、软件准备:
Bootstrap JDK: jdk-7u80-linux-x64.tar.gz
OpenJDK:openjdk-7u40-fcs-src-b43-26_aug_2013.zip
ANT:apache-ant-1.7.1-bin.zip
3、编译依赖:
安装alsa软件包:yum -y install alsa-lib-devel
安装 cups-devel:yum -y install cups-devel
安装lib相关库:yum -y install libX*
安装gcc:yum -y install gcc gcc-c++
安装freetype-2.4.11:
wget http://sourceforge.net/projects/freetype/files/freetype2/2.4.11/freetype-2.4.11.tar.gz/download tar -xvf freetype-2.4.11.tar.gz cd freetype-2.3.12 ./configure && make && make install
安装JDK:
解压缩jdk-7u80-linux-x64.tar.gz到/home/chaijuntao/Downloads/
设置环境变量vim /etc/profile
export JAVA_HOME=/home/chaijuntao/Downloads/jdk1.7.0_80 export JRE_HOME=/home/chaijuntao/Downloads/jdk1.7.0_80/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
使生效source /etc/profile
安装ant:
解压缩apache-ant-1.7.1-bin.zip到/home/chaijuntao/Downloads/
unzip apache-ant-1.7.1-bin.zip
ln -s /home/chaijuntao/Downloads/apache-ant-1.7.1/bin/ant /usr/bin/ant
检查java与ant:
解压缩openjdk-7u40-fcs-src-b43-26_aug_2013.zip到/home/chaijuntao/Downloads/
unzip openjdk-7u40-fcs-src-b43-26_aug_2013.zip
配置环境变量:
unset CLASSPATH unset JAVA_HOME export LANG=C export ALT_BOOTDIR=/home/chaijuntao/Downloads/jdk1.7.0_80 export ALLOW_DOWNLOADS=true export USE_PRECOMPILED_HEADER=true export ARCH_DATA_MODEL=64 export HOTSPOT_BUILD_JOBS=4 export ALT_PARALLEL_COMPILE_JOBS=4 export SKIP_DEBUG_BUILD=false export SKIP_FASTDEBUG_BUILD=true export DEBUG_NAME=debug export ALT_OUTPUTDIR=/home/chaijuntao/Downloads/openjdk/build
进入openjdk目录
4、编译检查
make sanity
若输出结果为:Sanity check passed
,表示设置正确
5、执行编译
make
6、更换jdk路径
vim /etc/profile
注释之前配置信息,更改jdk路径
export JAVA_HOME=/home/chaijuntao/Downloads/openjdk/build-debug/j2sdk-image export JRE_HOME=/home/chaijuntao/Downloads/openjdk/build-debug/j2sdk-image/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
使生效 source /etc/profile
7、查看java版本
[root@localhost j2sdk-image]# java -version openjdk version "1.7.0-internal-debug" OpenJDK Runtime Environment (build 1.7.0-internal-debug-root_2017_06_07_02_35-b00) OpenJDK 64-Bit Server VM (build 24.0-b56-jvmg, mixed mode)
异常处理:
1、解决libc.so.6: version `GLIBC_2.14' not found问题
(网上查询即可)
2、Error:./gamma: relocation error: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
修改文件:hotspot/make/linux/Makefile,去掉文件中所有的test_gamma即可