Include FXML throws Exception from .jar
up vote
0
down vote
favorite
I am trying to include an fxml file in another one and deploy my application as a runnable jar.
The top-level fxml file is loaded like this:
URL location = Editor.class.getClassLoader().getResource("view/app.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
Parent root = fxmlLoader.load();
appController = fxmlLoader.getController();
app.fxml, which is located in "src/view" contains this line:
<fx:include fx:id="console" source="console.fxml" />
Running this in eclipse will work as expected, but running the exported .jar file will print:
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: 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:834)
Caused by: javafx.fxml.LoadException:
view/app.fxml:92
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.load(FXMLLoader.java:2435)
at de.hsa.dice.editor.Editor.start(Editor.java:49)
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.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.net.MalformedURLException: Could not open InputStream for URL 'rsrc:console.fxml'
at org.eclipse.jdt.internal.jarinjarloader.RsrcURLConnection.getInputStream(RsrcURLConnection.java:49)
at java.base/java.net.URL.openStream(URL.java:1117)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2465)
at javafx.fxml.FXMLLoader.access$2700(FXMLLoader.java:105)
at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1154)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 12 more
Note that the console.fxml file is in the same package as app.fxml (in both the IDE and the .jar file).
That's why I also tried source="./console.fxml", but nothing changed.
java url include fxml executable-jar
add a comment |
up vote
0
down vote
favorite
I am trying to include an fxml file in another one and deploy my application as a runnable jar.
The top-level fxml file is loaded like this:
URL location = Editor.class.getClassLoader().getResource("view/app.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
Parent root = fxmlLoader.load();
appController = fxmlLoader.getController();
app.fxml, which is located in "src/view" contains this line:
<fx:include fx:id="console" source="console.fxml" />
Running this in eclipse will work as expected, but running the exported .jar file will print:
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: 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:834)
Caused by: javafx.fxml.LoadException:
view/app.fxml:92
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.load(FXMLLoader.java:2435)
at de.hsa.dice.editor.Editor.start(Editor.java:49)
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.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.net.MalformedURLException: Could not open InputStream for URL 'rsrc:console.fxml'
at org.eclipse.jdt.internal.jarinjarloader.RsrcURLConnection.getInputStream(RsrcURLConnection.java:49)
at java.base/java.net.URL.openStream(URL.java:1117)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2465)
at javafx.fxml.FXMLLoader.access$2700(FXMLLoader.java:105)
at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1154)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 12 more
Note that the console.fxml file is in the same package as app.fxml (in both the IDE and the .jar file).
That's why I also tried source="./console.fxml", but nothing changed.
java url include fxml executable-jar
nobody, really? I thought this might be a common scenario... because how else would anyone use the include tag in a production environment?
– EzPizza
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to include an fxml file in another one and deploy my application as a runnable jar.
The top-level fxml file is loaded like this:
URL location = Editor.class.getClassLoader().getResource("view/app.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
Parent root = fxmlLoader.load();
appController = fxmlLoader.getController();
app.fxml, which is located in "src/view" contains this line:
<fx:include fx:id="console" source="console.fxml" />
Running this in eclipse will work as expected, but running the exported .jar file will print:
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: 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:834)
Caused by: javafx.fxml.LoadException:
view/app.fxml:92
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.load(FXMLLoader.java:2435)
at de.hsa.dice.editor.Editor.start(Editor.java:49)
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.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.net.MalformedURLException: Could not open InputStream for URL 'rsrc:console.fxml'
at org.eclipse.jdt.internal.jarinjarloader.RsrcURLConnection.getInputStream(RsrcURLConnection.java:49)
at java.base/java.net.URL.openStream(URL.java:1117)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2465)
at javafx.fxml.FXMLLoader.access$2700(FXMLLoader.java:105)
at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1154)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 12 more
Note that the console.fxml file is in the same package as app.fxml (in both the IDE and the .jar file).
That's why I also tried source="./console.fxml", but nothing changed.
java url include fxml executable-jar
I am trying to include an fxml file in another one and deploy my application as a runnable jar.
The top-level fxml file is loaded like this:
URL location = Editor.class.getClassLoader().getResource("view/app.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
Parent root = fxmlLoader.load();
appController = fxmlLoader.getController();
app.fxml, which is located in "src/view" contains this line:
<fx:include fx:id="console" source="console.fxml" />
Running this in eclipse will work as expected, but running the exported .jar file will print:
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: 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:834)
Caused by: javafx.fxml.LoadException:
view/app.fxml:92
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.load(FXMLLoader.java:2435)
at de.hsa.dice.editor.Editor.start(Editor.java:49)
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.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.net.MalformedURLException: Could not open InputStream for URL 'rsrc:console.fxml'
at org.eclipse.jdt.internal.jarinjarloader.RsrcURLConnection.getInputStream(RsrcURLConnection.java:49)
at java.base/java.net.URL.openStream(URL.java:1117)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2465)
at javafx.fxml.FXMLLoader.access$2700(FXMLLoader.java:105)
at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1154)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 12 more
Note that the console.fxml file is in the same package as app.fxml (in both the IDE and the .jar file).
That's why I also tried source="./console.fxml", but nothing changed.
java url include fxml executable-jar
java url include fxml executable-jar
asked Nov 18 at 20:17
EzPizza
214
214
nobody, really? I thought this might be a common scenario... because how else would anyone use the include tag in a production environment?
– EzPizza
2 days ago
add a comment |
nobody, really? I thought this might be a common scenario... because how else would anyone use the include tag in a production environment?
– EzPizza
2 days ago
nobody, really? I thought this might be a common scenario... because how else would anyone use the include tag in a production environment?
– EzPizza
2 days ago
nobody, really? I thought this might be a common scenario... because how else would anyone use the include tag in a production environment?
– EzPizza
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I found the reason and a workaround for this issue.
The javafx.fxml.FXMLLoader class uses this URL constructor, when creating the FXMLLoader for included fxml files:
public URL(URL context, String spec)
using the location from the FXMLLoader(location) constructor as context and using the "source" from the include-element as spec.
So when loading my root fxml file with the path "view/app.fxml", the context will be the "view" package in my IDE, while it will be the root of the classpath in the exported .jar.
I tried creating the app-URL with
URL classpath = getClass().getProtectionDomain().getCodeSource().getLocation();
URL location = new URL(classpath, "view/app.fxml");
but my context will not be used again when this is plugged into the same constructor again later by the FXMLLoader.
So the only workaround I could think of is to just put all fxml-files (at least those with an include tag) into the root of a source-folder. That way, it will be located directly at the classpath in any environment.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I found the reason and a workaround for this issue.
The javafx.fxml.FXMLLoader class uses this URL constructor, when creating the FXMLLoader for included fxml files:
public URL(URL context, String spec)
using the location from the FXMLLoader(location) constructor as context and using the "source" from the include-element as spec.
So when loading my root fxml file with the path "view/app.fxml", the context will be the "view" package in my IDE, while it will be the root of the classpath in the exported .jar.
I tried creating the app-URL with
URL classpath = getClass().getProtectionDomain().getCodeSource().getLocation();
URL location = new URL(classpath, "view/app.fxml");
but my context will not be used again when this is plugged into the same constructor again later by the FXMLLoader.
So the only workaround I could think of is to just put all fxml-files (at least those with an include tag) into the root of a source-folder. That way, it will be located directly at the classpath in any environment.
add a comment |
up vote
0
down vote
accepted
I found the reason and a workaround for this issue.
The javafx.fxml.FXMLLoader class uses this URL constructor, when creating the FXMLLoader for included fxml files:
public URL(URL context, String spec)
using the location from the FXMLLoader(location) constructor as context and using the "source" from the include-element as spec.
So when loading my root fxml file with the path "view/app.fxml", the context will be the "view" package in my IDE, while it will be the root of the classpath in the exported .jar.
I tried creating the app-URL with
URL classpath = getClass().getProtectionDomain().getCodeSource().getLocation();
URL location = new URL(classpath, "view/app.fxml");
but my context will not be used again when this is plugged into the same constructor again later by the FXMLLoader.
So the only workaround I could think of is to just put all fxml-files (at least those with an include tag) into the root of a source-folder. That way, it will be located directly at the classpath in any environment.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I found the reason and a workaround for this issue.
The javafx.fxml.FXMLLoader class uses this URL constructor, when creating the FXMLLoader for included fxml files:
public URL(URL context, String spec)
using the location from the FXMLLoader(location) constructor as context and using the "source" from the include-element as spec.
So when loading my root fxml file with the path "view/app.fxml", the context will be the "view" package in my IDE, while it will be the root of the classpath in the exported .jar.
I tried creating the app-URL with
URL classpath = getClass().getProtectionDomain().getCodeSource().getLocation();
URL location = new URL(classpath, "view/app.fxml");
but my context will not be used again when this is plugged into the same constructor again later by the FXMLLoader.
So the only workaround I could think of is to just put all fxml-files (at least those with an include tag) into the root of a source-folder. That way, it will be located directly at the classpath in any environment.
I found the reason and a workaround for this issue.
The javafx.fxml.FXMLLoader class uses this URL constructor, when creating the FXMLLoader for included fxml files:
public URL(URL context, String spec)
using the location from the FXMLLoader(location) constructor as context and using the "source" from the include-element as spec.
So when loading my root fxml file with the path "view/app.fxml", the context will be the "view" package in my IDE, while it will be the root of the classpath in the exported .jar.
I tried creating the app-URL with
URL classpath = getClass().getProtectionDomain().getCodeSource().getLocation();
URL location = new URL(classpath, "view/app.fxml");
but my context will not be used again when this is plugged into the same constructor again later by the FXMLLoader.
So the only workaround I could think of is to just put all fxml-files (at least those with an include tag) into the root of a source-folder. That way, it will be located directly at the classpath in any environment.
answered 13 hours ago
EzPizza
214
214
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365036%2finclude-fxml-throws-exception-from-jar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
nobody, really? I thought this might be a common scenario... because how else would anyone use the include tag in a production environment?
– EzPizza
2 days ago