拉取 jdk8 的源码
这里准备了一份:https://github.com/susamlu/jdk20240618,branch:jdk8-b120
使用 Linux 编译 jdk8
系统版本:CentOS Linux release 7.9.2009 (Core)
安装 jdk7
下载地址:https://www.oracle.com/java/technologies/javase/javase7-archi...
- 我下载的是:jdk-7u80-linux-x64.tar.gz
- 解压:tar -zxvf jdk-7u80-linux-x64.tar.gz
配置:
- vim ~/.bash_profile
- source ~/.bash_profile
export JAVA_HOME=/home/jdk/jdk1.7.0_80 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
- 验证:java -version
编译过程
1. bash configure
configure: error: Could not find a C compiler. You might be able to fix this by running 'sudo yum groupinstall "Development Tools"'.
sudo yum groupinstall "Development Tools" -y
configure: error: Could not find X11 libraries. You might be able to fix this by running 'sudo yum install libXtst-devel libXt-devel libXrender-devel'.
sudo yum install libXtst-devel libXt-devel libXrender-devel -y
configure: error: Could not find cups! You might be able to fix this by running 'sudo yum install cups-devel'.
sudo yum install cups-devel -y
configure: error: Could not find freetype! You might be able to fix this by running 'sudo yum install freetype-devel'.
sudo yum install freetype-devel -y
configure: error: Could not find alsa! You might be able to fix this by running 'sudo yum install alsa-lib-devel'.
sudo yum install alsa-lib-devel -y
Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You do not have ccache installed. Try installing it.
You might be able to fix this by running 'sudo yum install ccache'.sudo yum install ccache -y
2. make clean
3. make all
Error: time is more than 10 years from present: 1388527200000
修改 jdk 源码:GenerateCurrencyData.java,10 年改成 100 年long time = format.parse(timeString).getTime(); if (Math.abs(time - System.currentTimeMillis()) > ((long) 10) * 365 * 24 * 60 * 60 * 1000) { throw new RuntimeException("time is more than 10 years from present: " + time); } --> long time = format.parse(timeString).getTime(); if (Math.abs(time - System.currentTimeMillis()) > ((long) 100) * 365 * 24 * 60 * 60 * 1000) { throw new RuntimeException("time is more than 100 years from present: " + time); }
编译成功,就可以测试了
测试 jdk8
配置:
- vim ~/.bash_profile
- source ~/.bash_profile
export JAVA_HOME=/home/jdk/jdk/build/linux-x86_64-normal-server-release/images/j2sdk-image export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
验证版本:java -version
openjdk version "1.8.0-internal" OpenJDK Runtime Environment (build 1.8.0-internal-jdk_2024_06_17_20_18-b00) OpenJDK 64-Bit Server VM (build 25.0-b62, mixed mode)
使用代码验证
测试代码:public class JvmTest { public static void main(String[] args) { System.out.println(System.getProperty("os.name")); System.out.println(System.getProperty("user.home")); System.out.println(System.getProperty("java.version")); System.out.println(System.getProperty("java.vendor.url")); } }
javac JvmTest.java
java JvmTestLinux /home/jdk 1.8.0-internal http://java.oracle.com/
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。