Let's say I'm developing a modular application that consists of 2 modules: com.spacey.explorer
that depends on com.spacey.rocket
module. I have their modular JAR files in some bin
directory.
And I want to prepare lightweight JRE to run it. So obviously, I use the jlink tool:
$ jlink --module-path /opt/jdk-9/jmods:../bin --add-modules com.spacey.explorer --output ~/custom-jre3
Now when I list 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 bundled into JRE. But if I wanted to build a JRE that has just JDK-originated modules that are sufficient to run my application and keep my application modules separate, I have to know what my JDK dependencies are (in the example this is just java.base
) and specify them explicitly like:
$ jlink --module-path /opt/jdk-9/jmods --add-modules java.base --output ~/custom-jre3
Is there any way to make jlink do this for me ? Or any tool that would figure out those JDK-originated dependencies for me?
You can use the jdeps tool. The option that could help is:
where
<path>
can be a pathname to a .class file, a directory, a JAR file.Note: Use
jdeps -help
to list out all the option and their syntax. You can useFor example, I gave a try to a jar file in my machines .m2 folder, which would be treated as an unnamed module like:
Output::
You can also make use of the
Update November 1,2017
There is future revision change to make use of the same with
jlink
as :