原本想在 Windows 下编译调试,但过程中遇到了诸多错误(老是报路径错误。。。),最后只好放弃。
此次记录调试的方法为 CentOS7 上编译,Windows 上使用 Clion 远程调试(也可直接在 CentOS7 桌面环境直接调试,速度快)。
一、下载源码(OpenJDK8)
yum 源使用的是阿里的 https://opsx.alibaba.com/mirror?lang=zh-CN
这里使用 mercurial(类似 Git 的版本控制系统) 下载源码,方便更新。
下面网址可以下载 mercurial 较新的版本。
https://mercurial.selenic.com/wiki/ChineseDownload
https://www.mercurial-scm.org/wiki/Download
# 或者 yum install hg -y yum install mercurial -y # 下载源码,目标目录需要为空 hg clone http://hg.openjdk.java.net/jdk8u/jdk8u /opt/jdk8u # 更新代码,操作和 Git 类似 hg pull # 获取完整源码(需要在源码目录下执行,下载时间较长,一次可能下载不成功,多试几次) cd /opt/jdk8u/ sh get_source.sh # 完全下载成功的打印信息。若输出中出现回滚字样,即代表下载过程中出错了,需重新执行下载脚本 No repositories to process. # Repositories: . corba jaxp jaxws langtools jdk hotspot nashorn .: cd . && hg pull -u corba: cd corba && hg pull -u jaxp: cd jaxp && hg pull -u jaxws: cd jaxws && hg pull -u langtools: cd langtools && hg pull -u jdk: cd jdk && hg pull -u hotspot: cd hotspot && hg pull -u nashorn: cd nashorn && hg pull -u .: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/ corba: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/corba jaxp: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/jaxp jaxws: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws jdk: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/jdk langtools: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/langtools hotspot: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot nashorn: 正在拉自 http://hg.openjdk.java.net/jdk8u/jdk8u/nashorn corba: 正在搜索修改 corba: 没有发现修改 jdk: 正在搜索修改 jdk: 没有发现修改 jaxws: 正在搜索修改 jaxws: 没有发现修改 .: 正在搜索修改 .: 没有发现修改 langtools: 正在搜索修改 langtools: 没有发现修改 hotspot: 正在搜索修改 hotspot: 没有发现修改 jaxp: 正在搜索修改 jaxp: 没有发现修改 nashorn: 正在搜索修改 nashorn: 没有发现修改
这里手动执行多次比较麻烦,自己写了个小脚本,循环执行。
#!/bin/bash for i in {1..28} do cd /opt/jdk8u/; sh ./get_source.sh; done
二、编译源码
Linux 下编译比 Windows 下简单太多。
https://hg.openjdk.java.net/jdk8u/jdk8u/raw-file/945f4ae40e43/README-builds.html
构建 JDK 8 需要使用 Update 7 或更高版本的 JDK 7 版本。JDK 8 开发人员不应使用 JDK 8 作为引导 JDK,以确保 JDK 8 依赖关系不会引入使用 JDK 7 构建的系统部分。
# 查询 yum list installed | grep jdk rpm -qa | grep jdk # 卸载 yum remove -y xxxxxxx # 验证 java -version # -bash: java: 未找到命令 # 安装 JDK7 # https://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html tar -zxf jdk-7u80-linux-x64.tar.gz -C /opt/
配置
cd /opt/jdk8u/ chmod +x configure # 直接执行配置,看看缺少什么工具或参数,按照错误提示安装和添加参数即可 ./configure # 安装编译所需工具包 yum install -y unzip zip libXtst-devel libXt-devel libXrender-devel cups-devel freetype-devel alsa-lib-devel fontconfig-devel yum groupinstall -y "Development Tools" # 配置编译环境 ./configure --with-boot-jdk=/opt/jdk1.7.0_80/ ##################################### 配置生产成功打印信息 ################################# A new configuration has been successfully created in /opt/jdk8u/build/linux-x86_64-normal-server-release using configure arguments '--with-boot-jdk=/opt/jdk1.7.0_80/'. Configuration summary: * Debug level: release * JDK variant: normal * JVM variants: server * OpenJDK target: OS: linux, CPU architecture: x86, address length: 64 Tools summary: * Boot JDK: java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 2 4.80-b11, mixed mode) (at /opt/jdk1.7.0_80) * Toolchain: gcc (GNU Compiler Collection) * C Compiler: Version 4.8.5 (at /usr/bin/gcc) * C++ Compiler: Version 4.8.5 (at /usr/bin/g++) Build performance summary: * Cores to use: 7 * Memory limit: 15884 MB WARNING: The result of this configuration has overridden an older configuration. You *should* run 'make clean' to make sure you get a proper build. Failure to do so might result in strange build problems.
configure 帮助文档
Running generated-configure.sh `configure' configures OpenJDK jdk8 to adapt to many kinds of systems. Usage: /opt/jdk8u/configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in