It is still possible to run a JavaFX application by using the classpath instead of module-path. There are 2 changes that we need to make to our previous sample to achive it:
run()
in HelloFX which will call Application.launch
methodLauncher.java
file with a main method to call HelloFX.run
methodrun()
in 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 {
@Override
public void start(Stage stage) {
Label l = new Label("Hello JavaFX!");
Scene scene = new Scene(new StackPane(l), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void run(String[] args) {
launch();
}
}
Launcher.java
file with a main method to call HelloFX.run
method:public class Launcher {
public static void main(String[] args) {
HelloFX.run(args);
}
}
javac -classpath \
$PATH_TO_FX/javafx.base.jar:$PATH_TO_FX/javafx.graphics.jar:$PATH_TO_FX/javafx.controls.jar:\
HelloFX.java Launcher.java
javac --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX.java
Add any additional jars used by the application. For example, if it is using FXML
functionality, add the javafx.fxml
module:
java -classpath \
$PATH_TO_FX/javafx.base.jar:$PATH_TO_FX/javafx.graphics.jar:$PATH_TO_FX/javafx.controls.jar:$PATH_TO_FX/javafx.fxml.jar\
Launcher
javac --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml HelloFX.java
java --module-path $PATH_TO_FX --add-modules javafx.controls HelloFX
java --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX
Checkout the OpenJFX samples repository for more samples.