javajavafxcomponentsruntimeexecutable-jar

Error: JavaFX runtime components are missing, and are required to run this application in generated jar using eclipse


I am getting the above error while running the JavaFX jar file on the command prompt or by double-clicking. I want the jar file to be run like an application by double-clicking on it. I have tried creating another class and calling the main function from that which inherits the JavaFX Application class. Please somebody help in resolving this error.

enter image description here

Please find this image

launch.class code:

package com.application;

public class launch {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Main.main(args);
}

}

Main.class code:

package com.application;

import java.io.File;

 import javafx.application.Application;

import javafx.application.Platform;

import javafx.event.EventHandler;

import       javafx.fxml.FXMLLoader;

 import       javafx.stage.Stage;

import               javafx.stage.WindowEvent;

 import              javafx.scene.Parent;

 import javafx.scene.Scene;

public class Main extends Application {

@Override

public void start(Stage primaryStage) {

    try {
        File del;
        try {
            del = new File("errorscanReport.txt");
            del.delete();
        } catch (Exception e) {
            // TODO Auto-generated catch block
        }
        
        try {
            del = new File("errorss.txt");
            del.delete();
        } catch (Exception e) {
            // TODO Auto-generated catch block
        }
        
        try {
            del = new File("error.txt");
            del.delete();
        } catch (Exception e) {
            // TODO Auto-generated catch block
        }
        try {
            File f = new File("AutoMoveError.txt");
            f.delete();
        }catch (Exception em) {
            // TODO: handle exception
        }
        
        Parent root = FXMLLoader.load(getClass().getResource("MainScene.fxml"));
        Scene scene = new Scene(root);
        primaryStage.setHeight(500);
        primaryStage.setWidth(700);
        primaryStage.setTitle("HUMANOID");
        primaryStage.setScene(scene);
        primaryStage.show();
        
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            
            @Override
            public void handle(WindowEvent arg0) {
                // TODO Auto-generated method stub
                MainSceneController.stop_flag = true;
                Platform.exit();
            }
        });
        
    } catch(Exception e) {
        System.out.println(e.toString());
    }
}

public static void main(String[] args) {
    launch(args);
}

}

Solution

  • You need to create a fat JAR.

    Take a look at this example projects. They both include a Task/Goal for creating a fat JAR. You can just double click on it and the application starts.

    You can either download one of this projects and edit it, or you can look how it is done.

    Example working JavaFX application with gradle https://github.com/davidweber411/JavaFxAppGradleNonModular

    Example working JavaFX application with maven https://github.com/davidweber411/JavaFxAppMavenNonModular

    Note: This are non modular applications.