How to Build the Java 9 JDK
Learn how to build JDK 9 from source code, just ahead of its imminent release. A step-by-step guide to get the new Java version running on your machine.
Java 9 is just around the corner, and at Jarroba we wanted to dedicate an article to showing how to build the JDK.
It’s a good idea to start checking how your applications behave on this new JDK. Even though it is backward compatible, they have removed some garbage collector options (DefNew + CMS, ParNew + SerialOld, Incremental CMS), for example, and G1 is now the default collector.
You can either use one of the early access compiled versions that you can find on the official page, or stay on the bleeding edge and have some fun with the source code.
Java 9 is not yet ready for production; it is expected to be ready on 2017/07/27, but it’s always a good idea to check whether we are prepared. For our personal projects it doesn’t matter which versions we use, and it’s always interesting to try the latest ones to see what the future holds. For production, we have to find the balance between being outdated and running the risk of losing support (including security updates, which is dangerous) and risking being on the latest version, since the software is not as well tested as software that has been around for a long time.
Building the JDK is not very common, since the best idea is to grab a binary and install it, but sometimes we feel like tinkering a bit, being on the cutting edge, we are impatient, or we want to contribute to the creation of the JDK through initiatives like adoptopenjdk.
This article is aimed at Mac OS X users. The steps for other operating systems are similar, but it has only been tested on OS X.
Requirements
- Mercurial (since the repository is in Mercurial).
- The latest JDK 8.
- freetype.
If you check some sites, they will tell you to install XQuartz and then run configure like this:
bash configure --with-freetype-include=/usr/X11/include/freetype2 --with-freetype-lib=/usr/X11/lib --disable-warnings-as-errors --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
JDKs are always built using the previous JDK. That is, to build JDK 7 you use JDK 6, for JDK 8 you use JDK 7, and for JDK 9 you use JDK 8.
Steps
Clone the repository
hg clone http://hg.openjdk.java.net/jdk9/jdk9
Go to the directory that was just created
cd jdk9
Now we have two options: either tell bash to run the script
bash ./get_source.sh
Or change its permissions (give it execute permissions) and run it
chmod u+x get_source.sh ./get_source.sh
Run the configuration
bash configure --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home --disable-warnings-as-errors
When it finishes, it will tell you something like:
==================================================== A new configuration has been successfully created in /Users/dionisio/jdk9/build/macosx-x86_64-normal-server-release using configure arguments '--with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home --disable-warnings-as-errors'. Configuration summary: * Debug level: release * HS debug level: product * JDK variant: normal * JVM variants: server * OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64 * Version string: 9-internal+0-adhoc.dionisio.jdk9 (9-internal) Tools summary: * Boot JDK: java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home) * Toolchain: clang (clang/LLVM from Xcode 8.3.2) * C Compiler: Version 8.1.0 (at /usr/bin/clang) * C++ Compiler: Version 8.1.0 (at /usr/bin/clang++) Build performance summary: * Cores to use: 8 * Memory limit: 16384 MB
Build the executables
make clean images
And that’s it, we have it. We can check that everything went well by running:
build/macosx-x86_64-normal-server-release/jdk/bin/java --version openjdk 9-internal OpenJDK Runtime Environment (build 9-internal+0-adhoc.dionisio.jdk9) OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.dionisio.jdk9, mixed mode)
One of the interesting things Java 9 brings is a REPL called JShell. REPL stands for read, eval, print and loop (like the Python console).
- Read: Reads what we type in.
- Eval: Evaluates what we have written.
- Print: Shows the result.
- Loop: Goes back to the start.
build/macosx-x86_64-normal-server-release/jdk/bin/jshell | Welcome to JShell -- Version 9-internal | For an introduction type: /help intro
jshell> System.out.println("Hola")
Hola
References
“How to Build the Java 9 JDK” by Dionisio Cortés at jarroba.com, licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0. Registered at Safe Creative.

You may also like
Advanced Dockerfile: Multi-Stage Builds, Registries, and Tricks
Free Docker course. Expert Docker tricks: multi-stage builds, optimizing images, faster build times, and distributing images through Docker registries.
Dockerfile: Directives and Dockerizing Projects
Free Docker course. A Dockerfile is a file of directives for building and deploying custom applications with Docker. Learn how to Dockerize your projects.



Leave a comment