Avoid the JAR hell with Java 9 Jigsaw
-
Make sure that you have disabled the gradle daemon (org.gradle.daemon = false).
-
Make sure that JAVA_HOME points to a version 9 jdk (early access build 111 or newer).
-
Build everything and run the app with
./gradlew run
.-
Only use the patched wrapper scripts that are shipped with this project.
-
-
The output will show that 2 versions of the same module have been loaded at the same time:
Loaded module 'com.greetings' from path 'hello2/build/libs/'. Will run its service(s) now: Greetings from version TWO! Loaded module 'com.greetings' from path 'hello1/build/libs/'. Will run its service(s) now: Greetings from version ONE!
Some background
The directories hello1 and hello2 contain almost the same code with just some small modification in the run() method. It simulates loading 2 different versions of the same module. It would be impossible to use both JARs in the same classpath. But it is possible to work around that limitation by constructing 2 Layer instances. That is what main code in Main.java is doing.
More information about Java 9 Jigsaw module system: http://openjdk.java.net/projects/jigsaw/
Gradle 2.12 is not yet ready for Jigsaw. The wrapper scripts have been patched to get the compiler running.
DEFAULT_JVM_OPTS="-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"