Issue
I've been researching this problem for a week. I have tried several Java IDEs in creating a JavaFX project but the problem continues. Does anyone know what this is about? I can not run the .jar file on the desktop and when I try run on the command line says:
java -jar mts.jar Error: Could not find or load main class mts.panel Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
My manifest file:
Implementation-Title: mts
X-COMMENT: Main-Class will be added automatically by build
Implementation-Version: 1.0
Permissions: sandbox
Codebase: *
JavaFX-Version: 8.0
Class-Path:
Created-By: JavaFX Packager
Implementation-Vendor: x
Main-Class: mts.panel
Java code:
package mts;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class panel extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Solution
Your desktop Java version doesn't include JavaFX. It's either too old (< Java 8) or too new (>= Java 11).
JavaFX has been removed for Java 11 (https://www.infoworld.com/article/3261066/javafx-will-be-removed-from-the-java-jdk.html). If you want to support Java 11, follow the instructions here: https://openjfx.io/openjfx-docs/
(since that link will eventually break, I googled for "java 11 javafx").
Answered By - Aaron Digulla