$ export JAVA_HOME=/path/to/jdk9 $ mvn test
The plugin will automatically add --add-modules java.se.ee on JVM argument in CLI (unless already specified by user) and all Java 9 API is provided to run your tests.
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.
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.