Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

Using JavaFX with Java 11 or Higher

56 sec read

jigsaw-javafx

In Java 11, JavaFX was removed from the SDK. It is now in its own separate module, and if you want to use it in your application you will need to specifically include it.

Where can I get the JavaFX SDK from?

The first thing you need to do is download JavaFX. More information about the JavaFX SDK can be found on the OpenJFX website here. You can download it from here.

How do I include it in a modular application?

If you are running a modular Java application from the command line, you need to add the JavaFX module to the classpath.

I have tested this with our Java PDF Library JPedal, as the Viewer has some features which require JavaFX. The command I used is:

java --module-path "path/to/javafx-sdk-11/lib" --add-modules=javafx.controls --add-modules=javafx.swing -jar "path/to/jpedal.jar"

In the example above:

–module-path “path/to/javafx-sdk-11/lib” adds the JavaFX SDK to the module path.

–add-modules=javafx.controls –add-modules=javafx.swing adds the specific JavaFX modules needed to run the application. JPedal requires the controls module and the swing module, so those are the 2 I have added. The list of the available modules can be found in the documentation here.

The good thing about modularisation is that you only use the bits you need to run your application. You don’t need the whole JavaFX SDK if you are not using all the modules. So you end up with a smaller, more lightweight program.

In our related other articles, we look at Java 8 vs Java 11,  Which JDK should I use now?



Our software libraries allow you to

Convert PDF to HTML in Java
Convert PDF Forms to HTML5 in Java
Convert PDF Documents to an image in Java
Work with PDF Documents in Java
Read and Write AVIF, HEIC, WEBP and other image formats
Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

One Reply to “Using JavaFX with Java 11 or Higher”

Comments are closed.