I am trying to create cross platform / platform independent executables for my JAVA-9 application / project jigsaw.
I think jlink command will create only platform specific executable/runtime.
JLink (covered by JEP 282) creates modular runtime images (covered by JEP 220, particularly the section New run-time image structure). These images are a generalization of JRE, JDK, and compact profiles and are OS specific like they are. JLink can hence not be used to create cross-platform executables.
That said, it is possible to run JLink on one operating system and create a runtime image for a different OS. All you have to do for that is to download and unpack a JDK 9 (same version as the one JLink comes from) for that and put its jmods
folder on the module path for the JLink call.
I know this question is old, but since it was one of the top Google results for me before posting my own question I decided to document my findings here as well.
Faced the same problem while attempting to create runtime images with jlink
for Java 11. The problem boiled down to incorrectly referencing the target JDK's jmods
folder which in turn meant that the JDK's modules weren't found in the module path. jlink
then defaulted to include the host JDK's module files (and corresponding binaries, libraries, etc) in the generated runtime image. By correctly referencing the target JDK's jmods
directory then the generated runtime image contains the platform-specific executables and accompanying files.
This was tested on a Windows machine by creating runtime images for Windows, Linux and MacOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With