Make targets, compilation process, build control, and advanced build techniques
Once you have a proper configuration, building the JDK is done using GNU Make. This page covers make targets, build control variables, and advanced compilation techniques.
# Build twice with newly built JDK (good for testing)make bootcycle-images# Remove all build results (keeps configuration)make clean# Remove everything including configurationmake dist-clean# Show important make targets and variablesmake help
All JDK source code is organized into modules (e.g., java.base, jdk.jdwp.agent).
# Build a single module and its dependenciesmake java.basemake jdk.jdwp.agent# Build multiple modulesmake jdk.crypto.cryptoki jdk.crypto.ec jdk.crypto.mscapi
Module dependencies are automatically built first.
# Build a specific phase (and dependencies)make gensrcmake javamake libs# Build a specific phase for a modulemake java.base-gensrcmake java.base-javamake jdk.jdwp.agent-libs
Example: Building java.base gensrc phase
# This builds only the gensrc phase for java.base# and any prerequisite phases it depends onmake java.base-gensrc
This is useful for quickly iterating on generated source code.
Build output is always saved to $BUILD/build.log (current) and build.log.old (previous).
CONF / CONF_NAME - Configuration selection
# Build specific configurationmake CONF=linux-x64-server-release# Build all matching configurations (substring)make CONF=debug# Build all configurationsmake CONF=# Build all except matchingmake CONF=!debug# Exact name match onlymake CONF_NAME=linux-x64-server-release
# Initial buildmake images# Edit a Java file in java.basevim src/java.base/share/classes/java/lang/String.java# Rebuild - only affected parts rebuildmake images
Incremental builds are optimized for developer productivity. In most cases, only changed files and their dependents are recompiled.
# Specify which tests to runmake test TEST="tier1"# Control test parallelismmake test TEST=tier1 TEST_JOBS=8# Pass options to test frameworkmake test TEST=tier1 TEST_OPTS="-verbose"# Pass VM optionsmake test TEST=tier1 TEST_VM_OPTS="-Xmx2g"
For complete testing documentation, see the Testing the JDK guide.
Cross-compilation requires a “Build JDK” (runs on build platform, not target platform).
# The build system creates a minimal Build JDK automatically# Or provide a pre-built one for speed:bash configure --openjdk-target=aarch64-linux-gnu \ --with-build-jdk=/path/to/build-jdk
The Build JDK must exactly match current sources, or the build may break in subtle ways.
# Configure for cross-compilationbash configure \ --openjdk-target=aarch64-linux-gnu \ --with-sysroot=/path/to/aarch64-sysroot \ --with-toolchain-path=/opt/cross/bin \ --with-boot-jdk=/usr/lib/jvm/java-21-openjdk# Buildmake images# Output is in build/linux-aarch64-server-release/images/jdk# Copy to target system and test:# ./bin/java -version
# Set fixed source date before configureexport SOURCE_DATE_EPOCH=946684800bash configure --with-version-opt=adhocmake images# Build again - should be byte-for-byte identicalmake dist-cleanbash configure --with-version-opt=adhocmake images
# Re-run configure with same argumentsmake reconfigure# Auto-reconfigure when neededexport CONF_CHECK=automake images # Automatically reconfigures if configure changed