Creating a custom runtime image for a specific modular application

Let's say I am developing a modular application consisting of 2 modules: com.spacey.explorerwhich depends on the module com.spacey.rocket. I have their modular JAR files in some bindirectory.

And I want to prepare a lightweight JRE to run. Therefore, obviously, I am using the jlink tool :

$ jlink --module-path /opt/jdk-9/jmods:../bin --add-modules com.spacey.explorer --output ~/custom-jre3

Now, when I list the modules in my JRE, I get the following:

$ java --list-modules 
com.spacey.explorer
com.spacey.rocket
java.base@9

That is, my application modules are combined in a JRE. But if I wanted to create a JRE that has only JDK-created modules sufficient to run my application and so that my application modules are separate, I should know that my JDK is dependencies (this is easy in the example java.base) and specify them explicitly:

$ jlink --module-path /opt/jdk-9/jmods --add-modules java.base --output ~/custom-jre3

Is there a way to make jlink do this for me? Or some tool that will define these JDK dependencies for me?

+6
source share
2 answers

You can use the jdeps tool . Possible variant:

jdeps --list-deps <path>

API JDK.

<path> .class, , JAR.

. jdeps -help, .


, jar .m2 , , :

jdeps --list-deps /.m2/repository/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.jar

::

java.base
java.desktop
unnamed module: /.m2/repository/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.jar

jdeps --jdk-internals --class-path <path> <path>

API JDK. -class-path , -include.


1,2017

, jlink :

jlink --module-path jmods --add-modules $(jdeps --print-module-deps myapp.jar) --output image
+8

jlink, --add-modules - , jlink . --add-modules com.spacey.explorer, jlink com.spacey.explorer .

JDK-, com.spacey.explorer , , jdeps (. nullpointer). , --add-modules.

:

$ jlink 
    --module-path /opt/jdk-9/jmods
    --add-modules java.base
    --output ~/custom-jre-for-explorer

, java.base, , java.sql, :

$ jlink 
    --module-path /opt/jdk-9/jmods
    --add-modules java.base,java.sql
    --output ~/custom-jre-for-explorer
+5

All Articles