Ambrish
Ambrish

Reputation: 305

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.

Upvotes: 18

Views: 5073

Answers (2)

rpsrosario
rpsrosario

Reputation: 111

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.

Upvotes: 2

Nicolai Parlog
Nicolai Parlog

Reputation: 51040

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.

Upvotes: 20

Related Questions