running JavaFX application after jpackage

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:

  1. 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 (via requires directives or --add-modules arguments).
  2. 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.

Leave a Comment