Fork me on GitHub

Java 9 in JAVA_HOME

$ export JAVA_HOME=/path/to/jdk9
$ mvn test

Using JDK Deprecated Modules

Since Java 9 some modules previously bundled with the JDK are disabled by default.

Version 2.20.1 of the plugin added automatically “–add-modules java.se.ee” option to the command line of forked JVMs (unless already specified by user) in order to ease the transition of applications to Java 9.

From 2.21 onwards the plugin will not add that option: the recommended way of using those modules is to add explicit dependencies of the maintained versions of such libraries.

This is a reference of the versions which were bundled with Java 8:

Commons Annotations

javax.annotation:javax.annotation-api:1.3.1

JavaBeans Activation Framework

javax.activation:javax.activation-api:1.2.0

Java Transaction API

javax.transaction:javax.transaction-api:1.2

JAXB

javax.xml.bind:jaxb-api:2.3.0

org.glassfish.jaxb:jaxb-runtime:2.3.0 (implementation)

JAX-WS

javax.xml.ws:jaxws-api:2.3.0

com.sun.xml.ws:jaxws-rt:2.3.0 (implementation)

The source code for each of these is maintained at https://github.com/javaee

Java 9 in configuration of plugin

The plugin provides you with configuration parameter jvm which can point to path of executable Java in JDK, e.g.:

<configuration>
    <jvm>/path/to/jdk9/bin/java</jvm>
</configuration>

Now you can run the build with tests on the top of Java 9.

Maven Toolchains with JDK 9

This is an example on Windows to run unit tests with custom path to Toolchain (-t …).

$ mvn -t D:\.m2\toolchains.xml test

Without (-t …) the Toolchain should be located in ${user.home}/.m2/toolchains.xml.

The content of toolchains.xml would become as follows however multiple different JDKs can be specified.

<toolchains xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>9</version>
      <vendor>oracle</vendor>
      <id>jdk9</id>
    </provides>
    <configuration>
      <jdkHome>/path/to/jdk9</jdkHome>
    </configuration>
  </toolchain>
</toolchains>

Your POM should specify the plugin which activates only particular JDK in toolchains.xml which specifies version 9:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-toolchains-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>toolchain</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <toolchains>
        <jdk>
          <version>9</version>
        </jdk>
      </toolchains>
    </configuration>
</plugin>

Now you can run the build with tests on the top of Java 9.