Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create cross platform executables for JDK9 application using JLink command

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.

like image 913
Ambrish Avatar asked May 13 '16 12:05

Ambrish


2 Answers

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.

like image 182
Nicolai Parlog Avatar answered Oct 04 '22 22:10

Nicolai Parlog


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.

like image 25
rpsrosario Avatar answered Oct 04 '22 20:10

rpsrosario