1. Overview
JDK hasn't been compiled manually, dare you say you're a Java programmer? (Brother By Sheep- JDK hasn't been compiled manually, dare you say you're a Java programmer? Actual Compile Java Source (JDK Source, JVM) Video Tutorial_ Bell-Bell-Bell_ bilibili)
- Compiling JDK by hand is theoretically a better JDK for your computer
- Maybe it would be fun to add your own DIY part to the source code?
- While reading the JDK source code, you can modify and test some of the features to include your own notes in the source code
This article is based on the Ubuntu virtual machine and uses JDK17 to compile JDK18 (which should be the latest official release version at the moment)
2. Install Ubuntu Virtual Machine
Install the virtual machine software, the author is using VMware
Download the UbuntuISO image on the Ubuntu website, the author downloaded Ubuntu20.04 desktop
The download address is:
Download Ubuntu Desktop System| Ubuntu
After downloading, start VMware and set up some configuration information of virtual machine. It is recommended to configure it to a larger size. After all, it is compiler and more CPU core will be faster
Once configured, mount the ISO image, start the virtual machine, configure some information (mainly password) for Ubuntu, and wait for the installation to complete
3. Configure Ubuntu
3.1. Configure SSH (optional)
Once the SSH tool is configured, SSH connections can be made and operated outside the virtual machine, and of course, directly inside the virtual machine.
sudo apt install openssh-server
Reference link: How to enable SSH - GlaryJoker - Blog Park (cnblogs.com) on Ubuntu 20.04
3.2. Download vim (optional)
vim is a terminal text editing tool commonly used on Linux, of course, you can choose other text tools
sudo apt install vim
3.3. Configure installation source
Ubuntu comes with a slower installation source, here the author configures the source of Ali cloud
Reference link:
Back up the original file (optional):
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
Delete the original file:
sudo rm -rf /etc/apt/sources.list
Edit the mirror file:
sudo vim /etc/apt/sources.list
Paste in the address given by the mirror station:
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
4. Install compilation tools
According to the compilation instructions officially given by openjdk ( Building the JDK (java.net) ), you need to install the following tools:
4.1. Toolchain
sudo apt-get install build-essential
4.2. Basic JDK (Boot JDK)
Need adjacent version of JDK, usually previous version
sudo apt-get install openjdk-17-jdk
4.3. Link Library
4.3.1. FreeType
sudo apt-get install libfreetype6-dev
4.3.2. CUPS
sudo apt-get install libcups2-dev
4.3.3. X11
sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev
4.3.4. ALSA
sudo apt-get install libasound2-dev
4.3.5. libffi
sudo apt-get install libffi-dev
4.4. Build Tools
4.4.1. Autoconf
Minimum version 2.69 required
sudo apt-get install autoconf
4.4.2. GNU Make
Minimum version 3.81 required
4.4.3. GNU Bash
Minimum version 3.2 required
5. Configure Configure
For specific configurations, see:
Default configuration here
6. Configure Make
For specific configurations, see:
Default configuration here
7. Compile JDK
Build Configuration
bash configure
- If the dependent libraries are not finished or have problems, install or modify them as prompted by the output
Compile All
make all
8. Compile output
After compilation, the compiled file is in the build folder
View files:
zhanny@ubuntu:~/Downloads/jdk18$ ls build/linux-x86_64-server-release/ bootcycle-spec.gmk build.log.old configure.log images make-support buildjdk-spec.gmk buildtools configure-support jdk spec.gmk build.log compare.sh hotspot Makefile support
Where images are the release s folder
zhanny@ubuntu:~/Downloads/jdk18$ ls build/linux-x86_64-server-release/images/ docs docs-javase docs-reference gengraphs jdk jmods sec-bin.zip symbols test
The common Java compilers are jdk's bin s under images
zhanny@ubuntu:~/Downloads/jdk18$ ls build/linux-x86_64-server-release/images/jdk/bin/ jar jconsole.debuginfo jlink jstack.debuginfo jar.debuginfo jdb jlink.debuginfo jstat jarsigner jdb.debuginfo jmap jstatd jarsigner.debuginfo jdeprscan jmap.debuginfo jstatd.debuginfo java jdeprscan.debuginfo jmod jstat.debuginfo javac jdeps jmod.debuginfo jwebserver javac.debuginfo jdeps.debuginfo jpackage jwebserver.debuginfo java.debuginfo jfr jpackage.debuginfo keytool javadoc jfr.debuginfo jps keytool.debuginfo javadoc.debuginfo jhsdb jps.debuginfo rmiregistry javap jhsdb.debuginfo jrunscript rmiregistry.debuginfo javap.debuginfo jimage jrunscript.debuginfo serialver jcmd jimage.debuginfo jshell serialver.debuginfo jcmd.debuginfo jinfo jshell.debuginfo jconsole jinfo.debuginfo jstack
9. References
[1]Building the JDK (java.net)
[2]openjdk/jdk18: JDK 18 development (github.com)
[3]True Hand-held, teach you to compile JDK-Short Books from scratch (jianshu.com)
[4]Actual Warfare: Compile your own JDK - Short Book (jianshu.com)