编译环境:
[操作系统]: CentOS7 64位
BootStrap JDK: 1.8.0_141
[root@localhost jdk8u-6d91dff0d6f1]# uname -a
Linux localhost.localdomain 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost jdk8u-6d91dff0d6f1]# java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)
- 下载openjdk源码
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u jdk8u
$ cd jdk8u
$ bash ./get_source.sh
如果因网速等原因下载不成功,可以先在浏览器打开代码库:
点击左边gz,下载gz包。我下载的为jdk8u-6d91dff0d6f1.tar.gz
解压后:进入目录jdk8u-6d91dff0d6f1,执行以下命令:
hg init jdk8u-6d91dff0d6f1
创建hgrc文件
[root@localhost jdk8u-6d91dff0d6f1]# cat .hg/hgrc
[paths]
default = http://hg.openjdk.java.net/jdk8u/jdk8u
default-pull = http://hg.openjdk.java.net/jdk8u/jdk8u
[ui]
username = Weimin Sun
chmod +x ./get_source.sh
bash ./get_source.sh
- 安装编译环境
安装alsa包
yum install alsa-lib-devel
安装cups-devel
yum install cups-devel
安装X相关的库
yum install libX*
yum install xrender
安装g++
yum install gcc gcc-c++
安装freetype
yum install freetype
安装ant
yum install ant
yum install ccache
- 设置环境变量
source build_jdk.env
内容如下:
unset CLASSPATH
unset JAVA_HOME
编译配置
./configure
或者
./configure --with-debug-level=fastdebug执行编译
make all
完成后会看到:
----- Build times -------
Start 2017-08-09 15:22:18
End 2017-08-09 15:57:08
00:00:44 corba
00:00:58 demos
00:04:56 docs
00:16:59 hotspot
00:01:17 images
00:00:26 jaxp
00:00:36 jaxws
00:07:33 jdk
00:00:58 langtools
00:00:22 nashorn
00:34:50 TOTAL
-------------------------
Finished building OpenJDK for target 'all'
- 配置jdk
便宜机器jdk环境:
[root@localhost bin]# java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)
编译后jdk目录:
[root@localhost bin]# pwd
/root/openjdk/jdk8u40/build/linux-x86_64-normal-server-release/jdk/bin
设置JAVA_HOME 和PATH
[root@localhost bin]# export JAVA_HOME=/root/openjdk/jdk8u40/build/linux-x86_64-normal-server-release/jdk
[root@localhost bin]# export PATH=/root/openjdk/jdk8u40/build/linux-x86_64-normal-server-release/jdk/bin:$PATH
[root@localhost bin]# java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-root_2017_08_09_15_21-b00)
OpenJDK 64-Bit Server VM (build 25.40-b25, mixed mode)