在 Linux (aarch64) 编译 OpenJDK 8
环境信息
- 操作系统:Rocky Linux 9.4 (aarch64)
- Open JDK:OpenJDK 8u422
- Boot JDK:jdk8u421-linux-aarch64
编译 OpenJDK 需要有一个 JDK。
解压后当前目录结构如下:
/opt/
├── jdk1.8.0_421
│ ├── COPYRIGHT
│ ├── LICENSE
│ ├── README.html
│ ├── THIRDPARTYLICENSEREADME.txt
│ ├── bin
│ ├── include
│ ├── jre
│ ├── legal
│ ├── lib
│ ├── man
│ ├── release
│ └── src.zip
└── jdk8u422-b05├── ASSEMBLY_EXCEPTION├── LICENSE├── Makefile├── README.md├── THIRD_PARTY_README├── common├── configure├── corba├── doc├── hotspot├── jaxp├── jaxws├── jdk├── langtools├── make├── nashorn└── test
进入 jdk8u422-b05
目录。
构建
一、运行 configure,配置编译环境
bash configure --with-boot-jdk=../jdk1.8.0_421
由于本机是 minimal 安装的,需要安装以下依赖:
yum install -y zip unzip make gcc libXtst-devel libXt-devel libXrender-devel cups-devel freetype-devel alsa-lib-devel fontconfig-devel g++
如果缺少依赖项而失败,按照提示安装后再次运行。
配置完成后,会输出以下信息:
A new configuration has been successfully created in
/opt/jdk8u422-b05/build/linux-aarch64-normal-server-release
using configure arguments '--with-boot-jdk=../jdk1.8.0_421Configuration summary:
* Debug level: release
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: linux, CPU architecture: aarch64, address length: 64Tools summary:
* Boot JDK: java version "1.8.0_421" Java(TM) SE Runtime Environment (build 1.8.0_421-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.421-b09, mixed mode) (at /opt/jdk1.8.0_421)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 11.4.1 (at /usr/bin/gcc)
* C++ Compiler: Version 11.4.1 (at /usr/bin/g++)Build performance summary:
* Cores to use: 1
* Memory limit: 1639 MB
二、编译 OpenJDK
make images
OpenJDK 8 不支持
--disable-warnings-as-errors
,会将所有warning
视为error
从而停止编译。需要将./hotspot/make/linux/makefiles/gcc.make
的WARNINGS_ARE_ERRORS = -Werror
注释掉。
编译完成后,输出以下信息:
----- Build times -------
Start 2024-09-21 22:56:18
End 2024-09-21 23:08:59
00:00:18 corba
00:00:24 demos
00:07:32 hotspot
00:00:24 images
00:00:10 jaxp
00:00:16 jaxws
00:03:12 jdk
00:00:18 langtools
00:00:07 nashorn
00:12:41 TOTAL
-------------------------
Finished building OpenJDK for target 'images'
编译成功后的 JDK 和 JRE 会在 ./build/linux-aarch64-normal-server-release
目录下的 j2re-image
和 j2sdk-image
。
三、验证结果
./build/linux-aarch64-normal-server-release/images/j2sdk-image/bin/java -version
编译成功,输出以下信息:
openjdk version "1.8.0_422-internal"
OpenJDK Runtime Environment (build 1.8.0_422-internal-root_2024_09_21_22_56-b00)
OpenJDK 64-Bit Server VM (build 25.422-b00, mixed mode)
参考资料
- jdk/doc/building.md