I am making a project in Eclipse using Maven and JavaFX and I am trying to load an FXML file as a scene using:
FXMLLoader menuLoader = new FXMLLoader(getClass().getResource(fxmlPath));
My fxmlPath is a valid path to a fxml file in my resources folder which is under the main folder under the src folder. When running this in eclipse it works however when I compile the project to an executable .jar file and try running it I get an error:
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @14462937'
/fxml/scenes/menu.fxml
null
java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2561)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2536)
at application.Main.loadScene(Main.java:148)
at application.Main.start(Main.java:189)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1570)
The location is not set error happens when you try and load an fxml file which doesn't exist and through using System.out.println() I found that getClass().getResource(fxmlPath) is null when the executable jar is run, even though the fxml file exists within the project.
Let me know if anyone has any ideas.