Reputation: 47
When ran locally from within IntelliJ my JavaFX application starts fine, but when it is compiled into a jar and then made accessible to users in the client I receive the following exception. Any idea as to why this could be?
(07:56:06) javafx.fxml.LoadException:
unknown path:10
(07:56:06) at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
(07:56:06) at javafx.fxml.FXMLLoader.access$700(Unknown Source)
(07:56:06) at javafx.fxml.FXMLLoader$ValueElement.processAttribute(Unknown
Source)
(07:56:06) at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttr
ibute(Unknown Source)
(07:56:06) at javafx.fxml.FXMLLoader$Element.processStartElement(Unknown So
urce)
(07:56:06) at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unkno
wn Source)
(07:56:06) at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
(07:56:06) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
(07:56:06) at javafx.fxml.FXMLLoader.load(Unknown Source)
(07:56:06) at scripts.MassFighter.GUI.Main.start(Main.java:22)
(07:56:06) at scripts.MassFighter.MassFighter.lambda$showAndWaitGUI$0(MassF
ighter.java:114)
(07:56:06) at scripts.MassFighter.MassFighter$$Lambda$351/222230364.run(Unk
nown Source)
(07:56:06) at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unkno
wn Source)
(07:56:06) at com.sun.javafx.application.PlatformImpl$$Lambda$53/1296636313
.run(Unknown Source)
(07:56:06) at java.security.AccessController.doPrivileged(Native Method)
(07:56:06) at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(U
nknown Source)
(07:56:06) at com.sun.javafx.application.PlatformImpl$$Lambda$52/47061671.r
un(Unknown Source)
(07:56:06) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Sou
rce)
(07:56:06) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
(07:56:06) at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown S
ource)
(07:56:06) at com.sun.glass.ui.win.WinApplication$$Lambda$43/157734934.run(
Unknown Source)
(07:56:06) at java.lang.Thread.run(Unknown Source)
(07:56:06) Caused by: java.lang.ClassNotFoundException: scripts.MassFighter.GUI.
Controller
(07:56:06) at java.net.URLClassLoader$1.run(Unknown Source)
(07:56:06) at java.net.URLClassLoader$1.run(Unknown Source)
(07:56:06) at java.security.AccessController.doPrivileged(Native Method)
(07:56:06) at java.net.URLClassLoader.findClass(Unknown Source)
(07:56:06) at java.lang.ClassLoader.loadClass(Unknown Source)
(07:56:06) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
(07:56:06) at java.lang.ClassLoader.loadClass(Unknown Source)
(07:56:06) ... 20 more
I have included the FXML file as a resource in the manifest:
<resource>scripts/resources/FighterDesign.fxml</resource>
Here is the code I use to find the resource and launch the application (Main.java):
private Controller controller;
@Override
public void start(Stage primaryStage) throws Exception {
InputStream in = MassFighter.class.getResourceAsStream("/scripts/MassFighter/GUI/FighterV1.fxml");
if (in != null) {
FXMLLoader loader = new FXMLLoader();
Parent root = loader.load(in);
primaryStage.setTitle("MassFighter V4");
primaryStage.setScene(new Scene(root));
controller = loader.getController();
controller.initialize();
primaryStage.setOnCloseRequest(event -> {
System.out.println("UI Closed - Stopping Script");
if (Environment.getScript().isRunning()) {
Environment.getScript().stop();
}
close();
});
primaryStage.show();
} else {
MassFighter.status = "Input Stream Unavailable"; // the input stream is not null when this error occurs
}
}
Here is where I link the FXML file to my controller:
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" opacity="0.89" prefHeight="431.0" prefWidth="672.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="scripts.MassFighter.GUI.Controller">
Here is the code I use to invoke the start method:
ui = new Main();
Platform.runLater(() -> {
try {
ui.start(new Stage());
} catch (Exception e) {
e.printStackTrace();
}
});
while (setupRunning) {
Execution.delay(100);
}
Platform.runLater(ui::close);
This is my project structure:
Any help is appreciated as I'm really puzzled! Thanks in advance.
Upvotes: 1
Views: 1000
Reputation: 5081
I had a similar problem loading a resource file from a JAR built on Windows and when it ran in Linux, see the solution for the following question ...
In your case you'll need to put in the applicable file/path names. Remember that the FMXL directory (if that's what you use) is going to be:
String fileName = "/fxml/this-under-resources.fxml";
Which in your project is under:
src/main/resources/
fxml/
this-under-resources.fxml
That syntax works OK but, if you don't know where your execution path is; you need to get the FXML source path equivalent for my HTML example, something very similar to:
jar:/fxml/this-under-resources.fxml
More or less. and then use code similar to the Jetty/HTML case, viz.
URL baseUrl = SplitFileServerRunner.class.getResource( baseStr );
String basePath = baseUrl.toExternalForm();
And so on.
Since that question, I've moved-on. I only wish to keep any presentation resources in the JAR for use a "fall-back" and as default views (or other resources).
The thing to recall about "external path" is that it is a run-time thing so every/anytime your run your JAR file; the answer ought to be correct. As long as you have suitable permissions and access rights. Good luck.
Upvotes: 1