running JavaFX application after jpackage
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 JARs included with the JavaFX SDK do not include the native code. Instead, said code is in the bin
directory. 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.- Note another way to get the JMOD files is to use a JDK distribution that includes JavaFX. Such distributions may no longer be provided by Oracle but other distributors still offer them (e.g. Azul Zulu, BellSoft Liberica, etc.). If you have a JDK that includes JavaFX then you don't need to place JavaFX on the
--module-path
, just make sure the JavaFX modules are resolved while packaging and during execution (viarequires
directives or--add-modules
arguments).
- Note another way to get the JMOD files is to use a JDK distribution that includes JavaFX. Such distributions may no longer be provided by Oracle but other distributors still offer them (e.g. Azul Zulu, BellSoft Liberica, etc.). If you have a JDK that includes JavaFX then you don't need to place JavaFX on the
-
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.
1. Note this extraction is done automatically by JavaFX.