I am getting the following error as Java 11 excluded the JavaFX as part of the latest version.
Error: JavaFX runtime components are missing, and are required to run this application
So how can I add JavaFX to Eclipse in Java 11? Thanks.
Following the getting started guide, these are the required steps to run JavaFX 11 from Eclipse.
Install Eclipse 2018-09 from here.
Install JDK 11 from here.
Add Java 11 as an installed JRE to Eclipse: Eclipse -> Window -> Preferences -> Java -> Installed JREs -> Add.
Download JavaFX 11 ea from here.
Create a User Library: Eclipse -> Window -> Preferences -> Java -> Build Path -> User Libraries -> New. Name it JavaFX11 and include the jars under the lib folder from JavaFX 11-ea.
Create a Java project. You don't need to add a module-path class. Make sure that you select Java 11 and you add the JavaFX11 library to the project's modulepath.
Add a package javafx11
and the main application class HelloFX
:
package javafx11;
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) {
String version = System.getProperty("java.version");
Label l = new Label ("Hello, JavaFX 11, running on "+version);
Scene scene = new Scene (new StackPane(l), 300, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Note that the editor shouldn't complain about JavaFX classes, as we have included the user library.
Add runtime arguments. Edit the project's run configuration, and add these VM arguments:
--module-path C:\Users<user>\Downloads\javafx-sdk-11\lib --add-modules=javafx.controls
Finally, run the project. It should work fine.