#StackBounty: #java #javafx #jar JavaFX .JAR file won't run on ubuntu 20.04 from terminal

Bounty: 50

I’m trying to build my javafx program into a .jar file. The program runs fine when i’m running it from intelliJ but won’t run from .jar file. I’m using intelliJ with java11 and javafx version 11. I followed all the instructions correctly to build the project into a .jar file but when i run my program i get some strange error (see below). I also checked javafx library in the .jar file and it’s there so i don’t know why i’m getting this error.

edit: I tried both on Windows and ubuntu but was still getting the error. I used to intelliJ to create the jar file using artefact feature. I made sure to attach javafx (external library) when building the artifact.

[Main.java]

package app;

import javafx.fxml.FXMLLoader;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import java.util.Objects;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("ui/index.fxml")));
        primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("data/NUIMLogoIcon.png"))));
        primaryStage.setScene(new Scene(root, 740, 600));
        primaryStage.show();
    }

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

[Launcher.java]

import app.Main;

public class Launcher {
    public static void main(String[] args) {
        Main.main(args);
    }
}

[index.fxml]

<ScrollPane focusTraversable="false"
            hbarPolicy="NEVER"
            maxHeight="-Infinity"
            maxWidth="720.0"
            minHeight="-Infinity"
            minWidth="-Infinity"
            prefHeight="1383.0"
            prefWidth="720.0"
            xmlns="http://javafx.com/javafx/11"
            xmlns:fx="http://javafx.com/fxml/1"
            fx:controller="app.ui.Controller"><!--   LINE 40-->
  <content>
    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="1374.0" prefWidth="720.0">
         <children>
         

[ERROR]

ninja@ninja-lat5410:~/Desktop/MULECodeLab/out/artifacts/MULECodeLab_jar$ java -jar MULECodeLab.jar 
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: javafx.fxml.LoadException: 
file:/home/ninja/Desktop/MULECodeLab/out/artifacts/MULECodeLab_jar/MULECodeLab.jar!/app/ui/index.fxml:40

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
    at app.Main.start(Main.java:15)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)

[Controller]

Controller.java

[Project repo]
Github Repo


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.