Chronicle Support Java 17

How to run Chronicle Libraries Under Java 17

On 14 September 2021, the long awaited Java 17 LTS version was released providing numerous improvements compared to older versions of Java such as improved performance, stability and security. To gain access to these improvements using the Chronicle libraries, there are some command line parameters that need to be passed in. In this short article we will describe how to do it.

Note that we currently support all widely used LTS variants of Java: 8, 11 & 17.

Chronicle Java 17 Support

Starting from chronicle-bom-2.22ea26, all new releases can be run under Java 17 when run on the class path (but not yet under the module path).

Strongly Encapsulated JDK Internals

One of the features introduced in Java 17 was “Strongly Encapsulated JDK Internals” as described in JEP 403 with the objective of providing a more robust and secure execution environment. Because Chronicle leverages tight integration with a small number of JDK internals to maintain high and consistent performance, there are some procedures that need to be executed in order to migrate to Java 17.

Note that we recommend to also apply below parameters when running with Java 11 (even though not all are required).

Command Line Parameters

When starting a JVM explicitly using the “java” command, the following command line parameters need to be passed in:

--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED

In many cases, these  parameters can be added via the environment variable JAVA_OPTS as similarly described in the next section.

Maven Integration

If you are using Maven to run code (e.g. using exec-maven-plugin exec:java), then you can set the MAVEN_OPTS environment variable as shown hereunder:

export MAVEN_OPTS="\
--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens=java.base/java.io=ALL-UNNAMED \
--add-opens=java.base/java.util=ALL-UNNAMED"

Java 11

Even though only a subset the above options is required when running under Java 11, we recommend providing the same command line options for Java 11 as for Java 17 as this will remove some warnings in the output logs.

Per Minborg

Per Minborg is an inventor and developer with more than 20 years of Java coding experience. He is a frequent contributor to open-source projects, an Oracle Groundbreaker Ambassador, an Oracle Code One alumnus and co-author of the publication Modern Java.

Subscribe to Our Newsletter