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

2

18

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.

Paediatrics answered 13/5, 2016 at 12:38 Comment(0)
E
19

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.

Eldoneldora answered 13/5, 2016 at 14:43 Comment(2)
It seems that it does not work. jlink does not copy appropriate executable files (java.exe, .dll, etc) from target JDK to the build. I've tried this on Linux with Windows JDK and it does not work this way.Salami
It should, though. Maybe you're doing it wrong? If you create a new question that describes exactly what you did and what didn't work, we can have a look at it.Eldoneldora
P
2

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.

Phoebe answered 7/2, 2021 at 8:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.