I have some really noob question. I tried to create installation for my test app with jpackage in OpenJDK 14. Here is what I did:
first, created custom JRE with
jlink --module-path "C:\Java\javafx-sdk-14\lib" --add-modules javafx.controls,javafx.fxml --output hello\myjre
and that was successful. I copied arguments from my Eclipse from Run Configurations. After that made installation with jpackage
jpackage --name HelloFX --input hello --main-jar HelloFX.jar --runtime-image hello\myjre
That created .msi file, I run it and it created entry in my Win10 applications. Of course, I have no idea how to find that in windows menu, but it is placed in my C:\Program Files\HelloFX. I located Icon and Application file with Duke image, when I tried to run application meesage "Failed to launch JVM" pop up.
Can someone help me, what am I doing wrong? I really want to make this work and dive deeply in JavaFX.
The JavaFX SDK does not embed the native code in the JAR files. It places the native code next to the JARs (e.g., in the bin
directory on Windows). That means your custom runtime image created by jlink
does not have the necessary native code to run JavaFX. You have two options:
Download the JMOD files from Gluon and use those when creating the custom runtime image. You would put the JMOD files on the --module-path
instead of the regular JAR files.
--module-path
, just make sure the JavaFX modules are resolved while packaging and during execution (via requires
directives or --add-modules
arguments).Use the JavaFX JARs that are published to Maven Central instead of the SDK. The Maven Central JARs embed the native code.
In both cases, make sure to use the JMOD/JAR files for your operating system—JavaFX is platform-specific.
I believe the first option is the best. When using JMOD files with jlink
the native code is included with the custom runtime image in the same way as the native code specific to the JRE. If you use the second approach the native code will still be included with the custom runtime image but it will have to be extracted to some location on your computer (e.g. <user-home>/.openjfx
) before it can be used1. In other words, the first option is cleaner.
Though as noted by trashgod, there is a potential third approach. Applications using the same version of JavaFX could share the cached extracted native libraries. This approach could be used to make your applications smaller. Just make sure at least one application embeds and extracts the native libraries first, or to place the native libraries in the cache location2 manually, before running the applications that don't embed the native code. Of course, this could be taken a step further by sharing an entire JavaFX SDK between multiple applications.
1. Note this extraction is done automatically by JavaFX.
2. The default cache location is ~/.openjfx/cache/<version>/<arch>
. You can set the javafx.cachedir
property to customize this.