torstenwerner / java-9-no-jar-hell

Using ModuleLayer instances to load conflicting versions of the same jar in the same JVM.

Home Page:http://openjdk.java.net/projects/jigsaw/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avoid the JAR hell with Java >= 9 Jigsaw

  • Make sure that JAVA_HOME points to a version 11 jdk.

    • On OS X:

      export JAVA_HOME=$(/usr/libexec/java_home 11)
  • Build everything and run the app with

    ./gradlew run
  • The output will show that 2 versions of the same module have been loaded at the same time:

    Greetings from version ONE!
    Greetings from version TWO!
  • You can see the output at travis-ci: https://travis-ci.org/torstenwerner/java-9-no-jar-hell

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 ModuleLayer 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/

I have tested it with gradle 5.0.

Continuous Integration thanks to Travis CI

Build status at Travis CI

Docker build

Instructions (use sudo on Linux):

docker pull openjdk:11-slim
docker build -t java-9-no-jar-hell .
docker run -it --rm java-9-no-jar-hell

IntelliJ bug

Switch to JDK 8 if the initial import of the gradle project fails. Switch to JDK 9 after the initial import.

About

Using ModuleLayer instances to load conflicting versions of the same jar in the same JVM.

http://openjdk.java.net/projects/jigsaw/

License:The Unlicense


Languages

Language:Java 86.1%Language:Shell 9.4%Language:Dockerfile 4.6%