Self-Contained Applications, built in Java

后端 未结 3 1494
遥遥无期
遥遥无期 2020-12-29 10:13

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 n

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 10:36

    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:

    • --module-path lists the folders that contain modules - this needs to include the platform modules shipped with the JDK you want to use (in $JAVA_HOME/jmods) and your application modules (mods)
    • --add-modules names the module(s) that you want your runtime image to contain - all of its (their) transitive dependencies are included
    • --launcher is optional, but very handy; it creates an OS-specific launcher (e.g. a .bat on Windows) with the given name (launch-app) that launches the specified module (your.app; in this case assuming the main class is defined for it)
    • --output specifies where to create the runtime image

提交回复
热议问题