您的位置:首页 > 运维架构 > Linux

CentOS7下编译openjdk

2015-12-02 16:12 721 查看

CentOS7下编译openjdk

编译环境:

操作系统: CentOS7 64位

BootStrap JDK: 1.7.0_76

1. 下载openjdk源码

下载openjdk1.7源码 openjdk-7u40-fcs-src-b43-26_aug_2013.zip

2. 安装编译环境

安装alsa包

yum install alsa-lib-devel

安装cups-devel

yum install cups-devel

安装X相关的库

yum install libX*

安装g++

yum install gcc gcc-c++

安装freetype

rpm -ivh freetype-2.4.11-9.el7.x86_64.rpm 下载地址

安装ant

tar -zvxf apache-ant-1.9.6-bin.tar.gz 下载地址

设置环境变量

unset CLASSPATH

unset JAVA_HOME

// 语言选项,必须设置

export LANG=C

// Bootstrap JDK的安装路径,必须设置

export ALT_BOOTDIR=/usr/java/jdk1.7.0_76

// Ant的安装路径

export ANT_HOME=/opt/apache-ant-1.9.6

// 允许自动下载依赖

export ALLOW_DOWNLOADS=true

// 预编译

export USE_PRECOMPILED_HEADER=true

// 64位jdk

export ARCH_DATA_MODEL=64

// 并行编译的线程数,设置为和CPU内核数量一致即可

export HOTSPOT_BUILD_JOB=4

export ALT_PARALLEL_COMPILE_JOBS=4

// 编译内容

export SKIP_DEBUG_BUILD=false

export SKIP_FASTDEBUG_BUILD=true

export DEBUG_NAME=debug

// 输出路径

export ALT_OUTPUTDIR=/root/openjdk/build

编译检查

make sanity

若输出结果为:
Sanity check passed
,表示设置正确

执行编译

make

配置debug版jdk

/root/openjdk/build-debug/j2sdk-image下内容为debug版jdk,将其复制到%JAVA_HOME%下,替换Oracle JDK。

查看jdk版本信息

[root@localhost ~]# java -version

openjdk version “1.7.0-internal-debug”

OpenJDK Runtime Environment (build 1.7.0-internal-debug-root_2015_12_02_11_03-b00)

OpenJDK 64-Bit Server VM (build 24.0-b56-jvmg, mixed mode)

3. 编译时出现的问题

1. /usr/bin/ld: cannot find -lstdc++

Linking vm...
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
/usr/bin/chcon: cannot access 'libjvm.so': No such file or directory
ERROR: Cannot chcon libjvm.so
/usr/bin/objcopy --only-keep-debug libjvm.so libjvm.debuginfo
/usr/bin/objcopy: 'libjvm.so': No such file
make[4]: *** [libjvm.so] Error 1
make[4]: Leaving directory `/usr/src/openjdk/hotspot/build/hotspot_debug/linux_amd64_compiler2/debug'
make[3]: *** [the_vm] Error 2
make[3]: Leaving directory `/usr/src/openjdk/hotspot/build/hotspot_debug/linux_amd64_compiler2/debug'
make[2]: *** [debug] Error 2
make[2]: Leaving directory `/usr/src/openjdk/hotspot/build/hotspot_debug'
make[1]: *** [generic_build2] Error 2
make[1]: Leaving directory `/usr/src/openjdk/hotspot/make'
make: *** [debug] Error 2


解决方法:

yum search libc++

yum install libstdc++-static

参考资料

2. ./gamma: relocation error: /usr/java/jdk1.7.0_76/jre/lib/amd64/libjava.so

Using java runtime at: /usr/java/jdk1.7.0_76/jre
./gamma: relocation error: /usr/java/jdk1.7.0_76/jre/lib/amd64/libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
make[5]: *** [jvmg] Error 127
make[5]: Leaving directory `/root/openjdk/build-debug/hotspot/outputdir'
make[4]: *** [generic_build2] Error 2
make[4]: Leaving directory `/root/Downloads/openjdk/hotspot/make'
make[3]: *** [jvmg] Error 2
make[3]: Leaving directory `/root/Downloads/openjdk/hotspot/make'
make[2]: *** [hotspot-build] Error 2
make[2]: Leaving directory `/root/Downloads/openjdk'
make[1]: *** [generic_debug_build] Error 2
make[1]: Leaving directory `/root/Downloads/openjdk'
make: *** [build_debug_image] Error 2


解决方法:删除hotspot/make/linux/MakeFile中所有的
test_gamma
参考资料

3. Error: time is more than 10 years from present: 1120165200000

Error: time is more than 10 years from present: 1120165200000
java.lang.RuntimeException: time is more than 10 years from present: 1120165200000
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[5]: *** [/root/openjdk/build/../build-debug/lib/currency.data] Error 1
make[5]: Leaving directory `/root/Downloads/openjdk/jdk/make/java/java'
make[4]: *** [all] Error 1
make[4]: Leaving directory `/root/Downloads/openjdk/jdk/make/java'
make[3]: *** [all] Error 1
make[3]: Leaving directory `/root/Downloads/openjdk/jdk/make'
make[2]: *** [jdk-build] Error 2
make[2]: Leaving directory `/root/Downloads/openjdk'
make[1]: *** [generic_debug_build] Error 2
make[1]: Leaving directory `/root/Downloads/openjdk'
make: *** [build_debug_image] Error 2


解决方法:修改CurrentDate.properties文件,将所有的时间改为10年以内。参考资料
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos openjdk