I have a test JavaFX program that runs fine in Eclipse. - I had to add a module-info file (module-info.java) containing the following:
module moduletest {
requires javafx.controls;
exports com.javafx.test.MenuTest;
}
Java class:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class MenuTest extends Application {
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(new VBox(), 300, 250);
Circle circle1 = new Circle(-20,0,200);
circle1.setFill(Color.CADETBLUE);
((VBox) scene.getRoot()).getChildren().addAll(circle1);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
When I run it as an exported JAR file using the following command
java -jar TonyJavaFX.jar -classpath .;./lib/javafx.controls.jar
, I get the following error:
Error: Could not find or load main class com.javafx.test.MenuTest.MenuTest Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
Note: I have a lib folder directly under the folder I am running the jar from, which contains all the JavaFX jar files.