posted on: 2019-03-14 06:14:08
New to java 9 is the module concept. OpenJFX is now distributed as a module.

To start with you need to download javafx. You only need the SDK for making and running programs, but if you want to use JLink to create a distributable package with the necessary jvm, you'll need the jmods package first.

Here is our "hello world" taken from here.

package hellofx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class HelloFX extends Application {

    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);

    public static void main(String[] args) {


Classic compilation and run, javac, jars, and .so's.

javac -cp -d build *.java

Because of the new module structure we cannot launch our application without using modules and we need to create an auxiliary file, it has been discussed here.

Our helper class:

package hellofx;

public class Launcher{
    public static void main(String[] args){

Then we can recompile, include some jars and include the directory containing .so's.

java -Djava.library.path=javafx-sdk-11.0.1/lib/ -cp hellofx.Launcher

Quite a buffer-full. The modules should make it easy. So if we do it correctly. We only need the original file.

javac --module-path javafx-sdk-11.0.1/lib --add-modules javafx.controls -d build

To run:

java --module-path javafx-sdk-11.0.1/lib --add-modules javafx.controls -cp build hellofx.HelloFX

So easy, and yet it can be simpler. Now we need another java file though.

module hellofx {
    requires javafx.controls;

    exports hellofx;

Now compiling is a little easier

javac --module-path javafx-sdk-11.0.1/lib/ -d build

So is running

java --module-path javafx-sdk-11.0.1/lib:build -m hellofx/hellofx.HelloFX

Finally there is jlink for bundling

  jlink --module-path jmods:build --add-modules=hellofx --output hellofx

Where jmods is the jmods package where the sdk was acquired.

  ./hellofx/bin/java -m hellofx/hellofx.HelloFX