0

I have written a javaFX windows application that runs great from within eclipse. I'd like to deploy it so that it can be executed on other windows computers. I have exported it as a runnable jar file. However, when I try to execute it, I get an Exception in application start method.

All the information I see online says I need to copy the VM Arguments from the project's run configurations. However, my VM Arguments text box in my project is completely blank.

I'm using eclipse with e(fx)clipse plugin installed. My project execution environment is 'JavaSE-1.8 (jre1.8.0_161)'

Here is the output when I try to run my application:

java -jar my_exported_jar.jar
Exception in Application start method
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Location is not set.
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
        at com.st.myst25app.MainApp.initStage(MainApp.java:52)
        at com.st.myst25app.MainApp.start(MainApp.java:36)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
        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$null$148(WinApplication.java:191)
        ... 1 more
Exception running application com.st.myst25app.MainApp
benino
  • 577
  • 2
  • 6
  • 16
  • 2
    This might help: https://stackoverflow.com/questions/17228487/javafx-location-is-not-set-error-message – majusebetter Nov 06 '22 at 21:05
  • *"I'd like to deploy it so that it can be executed on other windows computers. I have exported it as a runnable jar file."* -> how will you ensure the other computer is setup to run your jar using JRE 8? – jewelsea Nov 07 '22 at 11:03

1 Answers1

0

I figured it out! Here are the lines of code where I was instantiating my FXMLLoader

FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/myfxml.fxml"));

I changed it to a full path from the root of my application and it worked:

FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("/src/path/to/view/myfxml.fxml"));
benino
  • 577
  • 2
  • 6
  • 16
  • It is unusual to have the `src` directory as part of the path of a deployed resource. Standard resource structure, deployments and lookups are discussed in [How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?](https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other) and the eden resource guide linked from that answer. – jewelsea Nov 07 '22 at 11:08