Ubuntu下编译JDK
JDK源码
JDK安装包(boot jdk)
从adoptium下载
安装boot jdk
修改PATH搜索顺序来访问自己的jdk,避免和系统已存在的jdk冲突。
$ mkdir ~/jdk
$ cd ~/jdk
$ tar zxvf jdk-17_linux-aarch64_bin.tar.gz
$ ln -s ~/jdk/jdk-17.0.5 ~/jdk/jdk
$ vim ~/.bashrc
export JAVA_HOME=~/jdk/jdk
export PATH=${JAVA_HOME}/bin:$PATH
export CLASSPATH=.:${JAVA_HOME}/lib
$ source ~/.bashrc
之后切换软连接~/jdk/jdk
来切换java版本:
$ rm ~/jdk/jdk
$ ln -s ~/jdk/jdk-11.0.17 ~/jdk/jdk
$ java -version
java version "11.0.17" 2022-10-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.17+10-LTS-269)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.17+10-LTS-269, mixed mode)
亦可以在编jdk的configure中使用--with-boot-jdk=/home/xxx/jdkxxx
来指定boot jdk
编译jdk
编译jdk需要对应版本的gcc,以ubuntu 20 LTS为例.
- jdk11编译需求:4.8 <= gcc <= 7.x 或 clang >= 3.2, 需要一个已编译好的jdk N-1 作为boot jdk
- jdk17编译需求:5.0 <= gcc <= 10.2 或 clang >= 3.5, 需要一个已编译好的jdk N-1 作为boot jdk
安装编译环境:
$ sudo apt-get install build-essential
$ sudo apt-get install autoconf
$ sudo apt-get install zip
$ sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libxrandr-dev
$ sudo apt-get install libcups2-dev
$ sudo apt-get install libfontconfig1-dev
$ sudo apt-get install libasound2-dev
$ sudo apt-get install gcc-7 g++-7
$ ls /usr/bin/ | grep gcc
aarch64-linux-gnu-gcc-7
aarch64-linux-gnu-gcc-ar-7
aarch64-linux-gnu-gcc-nm-7
aarch64-linux-gnu-gcc-ranlib-7
gcc-7
gcc-ar-7
gcc-nm-7
gcc-ranlib-7
进行编译并测试
$ git clone https://github.com/openjdk/jdk11u.git
$ cd jdk11u
$ bash ./configure --with-extra-cxxflags="-Wno-error" \
--with-extra-cflags="-Wno-error" \
--enable-unlimited-crypto \
--with-native-debug-symbols=none \
--with-debug-level=release \
--with-target-bits=64 \
CC=/usr/bin/gcc-7 \
CXX=/usr/bin/g++-7
$ make images
$ ./build/linux-aarch64-normal-server-release/images/jdk/bin/java -version
参考:jdk8u build