-
Notifications
You must be signed in to change notification settings - Fork 0
Making your own OpenJDK distro
Wikipedia introduces OpenJDK as the below,
OpenJDK (Open Java Development Kit) is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GPL-2.0-only with a linking exception. Were it not for the GPL linking exception, components that linked to the Java Class Library would be subject to the terms of the GPL license. OpenJDK is the official reference implementation of Java SE since version 7.
Since OpenJDK source codes are available in public, anyone can make his/her own OpenJDK builds. In real world, there are some well-known OpenJDK distros, such as Eclipse Temurin, Azul Zulu, Amazon Corretto and SAP SapMachine.
In the past, exactly before September in 2020, OpenJDK source repositories were hosted by hg.openjdk.org and used Mercurial (hg). After that point, the repositories were moved to GitHub and are using git now.
The GitHub account for OpenJDK is openjdk, and it has a lot of repositories, including:
- jdk, the mainline repository hosting the most modern and mature features.
- jdk21u, this repository is used for releasing OpenJDK 21 update builds.
- jdk17u, this repository is used for releasing OpenJDK 17 update builds.
- jdk11u, this repository is used for releasing OpenJDK 11 update builds.
- jdk8u, this repository is used for releasing OpenJDK 8 update builds.
Besides the JDK repositories, this GitHub account has some other repositories for exploring future JDK features and JDK-related tools. However, this post just focus on the mainline repository.
OpenJDK supports a set of system platforms, including Linux x86_64/aarch64/ppc64/ppc64le, macOS x86_64/aarch64, Windows x86_64 and AIX ppc64. In fact, some OpenJDK vendors support even more CPU architectures, like LoongArch.
It's easy to build OpenJDK on the mainstream platforms, like Linux x86_64/aarch64, macOS x86_64/aarch64 and Windows x86_64. The toolchains should be already there, or at least it is very convenient to acquire them on the platforms' modern versions. This post is going to build OpenJDK on macOS x86_64.
Building OpenJDK on a MacBook Pro should be straightforward. The belows are the infos of the Mac and Xcode used by this post.
% system_profiler SPHardwareDataType
Hardware:
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro16,1
Processor Name: 6-Core Intel Core i7
Processor Speed: 2.6 GHz
...
% system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: macOS 14.1.1 (23B81)
Kernel Version: Darwin 23.1.0
...
% xcodebuild -version
Xcode 14.1
Build version 14B47b
It is interesting that building a JDK needs a pre-existing JDK, called "boot JDK". Building with different JDK repositories needs different boot JDK versions. Version 21+ is required for building JDK from the mainline repository. This post uses a Eclipse Temurin 21.0.1 as the boot JDK.
Before further action, let's give this new OpenJDK derivative a name. Java is one of coffee beans, and some OpenJDK distros are named with a coffee bean, for example Amazon Corretto. So, here also names this OpenJDK with a coffee bean, exactly Jember.
Of course, it has to clone the OpenJDK mainline source repository to a local directory.
% git clone https://github.com/openjdk/jdk.git openjdk-src
Enter the local directory openjdk-src
and find the following stuffs.
% ls
ADDITIONAL_LICENSE_INFO CONTRIBUTING.md Makefile bin doc src
ASSEMBLY_EXCEPTION LICENSE README.md configure make test
Like many open source projects, OpenJDK building also depends on make
. So, it needs to configure the making at first.
% bash configure \
--with-boot-jdk=/path/to/openjdk21 \
--with-version-string=23 \
--with-version-build=8 \
--with-vendor-name="John Jiang" \
--with-vendor-version-string=Jember \
--with-vendor-url=https://github.com/johnshajiang \
--with-vendor-bug-url=https://bugs.openjdk.java.net
Although the above options are self-described, here introduces them briefly.
-
--with-boot-jdk
sets the path to the boot JDK. -
--with-version-string
specifies the version string this build will be identified with. -
--with-version-build
sets the build number. The value is an integer for JDK 9+, a string for JDK 8. -
--with-vendor-name
sets the vendor name. -
--with-vendor-version-string
sets the string displayed in the version information. Generally, it's the name of the JDK distro. That's whyJember
is here. -
--with-vendor-url
sets the vendor web page for the JDK distro. -
--with-vendor-bug-url
specifies the web page the bugs should be reported to. Here uses JDK Bug System, which is the OpenJDK official bug tracking system. Please note that OpenJDK doesn't use GitHub Issues to track bugs.
Besides setting the JDK properties, the configuration also checks if the required dependencies are ready. If all stuffs are in-position, you should find a configuration summary,
Configuration summary:
* Name: macosx-x86_64-server-release
* Debug level: release
* HS debug level: product
* JVM variants: server
* JVM features: server: 'cds compiler1 compiler2 dtrace epsilongc g1gc jfr jni-check jvmci jvmti management parallelgc serialgc services shenandoahgc vm-structs zgc'
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 23+8 (23)
...
After the configuration, it's time to make.
% make images
If the making ends up with the following line, that means it is finished successfully.
Finished building target 'images' in configuration 'macosx-x86_64-server-release'
A new directory named build
is created and the new built JDK binary is there.
% ls build/macosx-x86_64-server-release/images/jdk
bin conf demo include jmods legal lib man release
Great! Have a new OpenJDK distro! Certainly, the version information displays the new JDK's version, build number and name.
% build/macosx-x86_64-server-release/images/jdk/bin/java -version
openjdk version "23" 2024-09-17
OpenJDK Runtime Environment Jember (build 23+8)
OpenJDK 64-Bit Server VM Jember (build 23+8, mixed mode, sharing)
But where are the vendor properties specified by the configuration? Don't worry, the below command with opton -XshowSettings
unveils them.
% build/macosx-x86_64-server-release/images/jdk/bin/java -XshowSettings:properties -version 2>&1 | grep java.vendor
java.vendor = John Jiang
java.vendor.url = https://github.com/johnshajiang
java.vendor.url.bug = https://bugs.openjdk.java.net
java.vendor.version = Jember