OpenJDK编译

说明

操作系统:CentOS7
OpenJDK源码:openjdk-7u40-fcs-src-b43-26_aug_2013
JDK:jdk-6u24-linux-i586.bin
ANT:apache-ant-1.7.1-bin.tar.gz

为了方便操作,也可以从这里统一下载,请戳我的文件柜

安装必要软件

  1. 安装JDK6
    将jdk-6u24-linux-i586.bin文件上传到CentOS上
    如果没有执行权限,先执行如下命令
chmod 777 ./jdk-6u24-linux-i586.bin

执行安装程序

./jdk-6u24-linux-i586.bin

配置环境变量,修改/etc/profile文件,增加如下的内容

JAVA_HOME=/home/linxm/jdk1.6.0_24
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
  1. linux声音框架
    Advanced Linux Sound Architecture (ALSA) (Linux only)
yum install alsa-lib-devel
  1. 打印框架
    Common UNIX Printing System (CUPS) Headers (Solaris & Linux)
yum install cups-devel
  1. 安装X相关的库
yum install libX*
  1. 安装g++
yum install gcc gcc-c++
  1. 安装FreeType2
    为访问字体文件提供了一套统一的、独立于字体文件类型的、简单而易用的API。通常上面的步骤执行之后,已经自动安装了
  2. ANT安装
# 下载文件
wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.tar.gz
tar -zxvf apache-ant-1.7.1-bin.tar.gz
mv apache-ant-1.7.1 /usr/local/ant 

编辑配置文件/etc/profile,怎讲如下的内容

ANT_HOME=/usr/local/ant
PATH=$JAVA_HOME/bin:${ANT_HOME}/bin:$PATH
export ANT_HOME

为了马上生效,执行下面的命令

source /etc/profile

进行必要的环境变量配置

修改/etc/profile文件,增加如下的内容

export LANG=C
export ALT_BOOTDIR=$JAVA_HOME
export ALT_JDK_IMPORT_PATH=$JAVA_HOME
export ALLOW_OWNLOADS=true
unset CLASSPATH
unset JAVA_HOME

进行编译

  1. 将OpenJDK代码上传到CentOS上
  2. 进入OpenJDK目录内
  3. 进行make检查
    执行命令
make sanity

如果没有问题执行编译

make

问题解决

  1. 编译中发生** cannot find -lstdc++**错误
Linking vm...
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
ln: failed to access 'libjvm.so.1': Too many levels of symbolic links
/usr/bin/objcopy --only-keep-debug libjvm.so libjvm.debuginfo
/usr/bin/objcopy: Warning: could not locate 'libjvm.so'.  reason: Too many levels of symbolic links
make[6]: *** [libjvm.so] Error 1
make[6]: Leaving directory `/home/linxm/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product'
make[5]: *** [the_vm] Error 2
make[5]: Leaving directory `/home/linxm/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product'
make[4]: *** [product] Error 2
make[4]: Leaving directory `/home/linxm/openjdk/build/linux-amd64/hotspot/outputdir'
make[3]: *** [generic_build2] Error 2
make[3]: Leaving directory `/home/linxm/openjdk/hotspot/make'
make[2]: *** [product] Error 2
make[2]: Leaving directory `/home/linxm/openjdk/hotspot/make'
make[1]: *** [hotspot-build] Error 2
make[1]: Leaving directory `/home/linxm/openjdk'
make: *** [build_product_image] Error 2

解决方法

yum search libc++ 
yum install libstdc++-static 
  1. 发现libjvm.so软连接死循环问题
Linking vm...
/usr/bin/ld: cannot open output file libjvm.so: Too many levels of symbolic links
collect2: error: ld returned 1 exit status
ln: failed to access 'libjvm.so': Too many levels of symbolic links
ln: failed to access 'libjvm.so.1': Too many levels of symbolic links
/usr/bin/objcopy --only-keep-debug libjvm.so libjvm.debuginfo
/usr/bin/objcopy: Warning: could not locate 'libjvm.so'.  reason: Too many levels of symbolic links
make[6]: *** [libjvm.so] Error 1
make[6]: Leaving directory `/home/linxm/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product'
make[5]: *** [the_vm] Error 2
make[5]: Leaving directory `/home/linxm/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product'
make[4]: *** [product] Error 2
make[4]: Leaving directory `/home/linxm/openjdk/build/linux-amd64/hotspot/outputdir'
make[3]: *** [generic_build2] Error 2
make[3]: Leaving directory `/home/linxm/openjdk/hotspot/make'
make[2]: *** [product] Error 2
make[2]: Leaving directory `/home/linxm/openjdk/hotspot/make'
make[1]: *** [hotspot-build] Error 2
make[1]: Leaving directory `/home/linxm/openjdk'
make: *** [build_product_image] Error 2

我进入home/linxm/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product目录,发现libjvm.so文件不存在,具体什么原因导致不清楚

make clean
make sanity
make
  1. 发现超过10年的问题
Error: time is more than 10 years from present: 1136059200000
java.lang.RuntimeException: time is more than 10 years from present: 1136059200000
        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]: *** [/home/linxm/openjdk/build/linux-amd64/lib/currency.data] Error 1
make[4]: Leaving directory `/home/linxm/openjdk/jdk/make/java/java'
make[3]: *** [all] Error 1
make[3]: Leaving directory `/home/linxm/openjdk/jdk/make/java'
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/linxm/openjdk/jdk/make'
make[1]: *** [jdk-build] Error 2
make[1]: Leaving directory `/home/linxm/openjdk'
make: *** [build_product_image] Error 2

修改/jdk/src/share/classes/java/util/CurrencyData.properties文件
将其中10年以前的时间都设置到10年以内

验证

编译成功

#-- Build times ----------
Target all_product_build
Start 2016-11-29 15:29:09
End   2016-11-29 15:55:26
00:00:22 corba
00:00:22 hotspot
00:00:04 jaxp
00:00:11 jaxws
00:25:11 jdk
00:00:05 langtools
00:26:16 TOTAL
-------------------------
make[1]: Leaving directory `/home/linxm/openjdk'

查看一下版本

cd build/linux-amd64/bin
./java -version

显示如下内容

openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-root_2016_11_29_14_43-b00)
OpenJDK 64-Bit Server VM (build 24.0-b56, mixed mode)

设置一下路径

export JAVA_HOME=/home/linxm/openjdk/build/linux-amd64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

可以书写一个最基本的Java程序运行一下!!

你可能感兴趣的:(OpenJDK编译)