javajava-9self-containedjava-module

Self-Contained Applications, built in Java


I've watched a few online presentations that briefly mentioned self-contained applications in Java 9, but I have a question that I would like cleared up.

With the new module system, you're now allowed to only include the minimum amount of code required to run your application. However, does the system that wishes to run the application still require the JRE, or is that something that can be included in the base module within the program?

I suspect it's the latter, as the page (here) to download the newest version of Java still shows version 8_151.

TL;DR - Using Java 9, is it possible to create a self-contained executable that can be executed on a system without the JRE/Java installed?


Solution

  • jlink

    Yes, this is possible with jlink (JEP 282), but all of your code and your dependencies need to be modular JARs (i.e. ones with module-info.class). It works like this:

    jlink
        --module-path $JAVA_HOME/jmods:mods
        --add-modules your.app
        --launcher launch-app=your.app
        --output your-app-image
    

    In detail: