拉取 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...

  1. 我下载的是:jdk-7u80-linux-x64.tar.gz
  2. 解压:tar -zxvf jdk-7u80-linux-x64.tar.gz
  3. 配置:

    • 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
  4. 验证:java -version

编译过程

1. bash configure

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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

  1. 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

  1. 配置:

    • 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
  2. 验证版本: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)
  3. 使用代码验证
    测试代码:

    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 JvmTest

    Linux
    /home/jdk
    1.8.0-internal
    http://java.oracle.com/

三穆
1 声望1 粉丝

沉舟侧畔千帆过,病树前头万木春。


引用和评论

0 条评论