Search code examples
javajava-platform-module-system

"Essential" (Jigsawed) Java 9 JRE without modularized code


We have a Java application that does not use AWT/Swing/JavaFX and works fine with a private bundled JRE 8. JRE 9 is significantly larger than JRE 8 but we want to let the users try our application with JRE 9. We don't yet want to modularize our code or the jars (to keep compatibility with Java 8).

How to create an "essential" (= stripped down to the minimal required parts), private JRE 9 that could be bundled with that Java application?


Solution

  • It is possible to create custom runtime-images of the JRE without having converted the application itself to Java 9 modules. First, we need to find out what modules (of the JDK/JRE) are needed:

    "C:\Program Files\Java\jdk-9.0.1\bin\jdeps.exe"
                     -s
                     "C:\path\to\my\jars\*.jar"
    

    Then we can create a light-weight jre directory structure (replace java.logging,java.xml with the modules required by your application):

    "C:\Program Files\Java\jdk-9.0.1\bin\jlink.exe"
                     --module-path "C:\Program Files\Java\jdk-9.0.1\jmods"
                     --add-modules java.logging,java.xml
                     --output "e:\myproject\jre"