JavaFX通过Exe4J打包为EXE后失败运行
JavaFX failed to run after being packaged as EXE through Exe4J
我用JavaFX构建的项目在编译器中运行良好,但是当我将其打包为EXe可执行文件时却出错了。
运行打包EXE程序时提示的错误信息如下:
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(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2459)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
at cn.ambit.app.App.start(App.java:40)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater(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(WinApplication.java:174)
... 1 more
发生错误的函数:
@Override
public void start(Stage initStage) throws Exception {
FXMLLoader initFXMLLoader = new FXMLLoader(App.class.getResource("/view/initializationStage.fxml"));
AnchorPane anchorPane = initFXMLLoader.load(); // line 40
Scene scene = new Scene(anchorPane);
JMetroThemeManager.setSceneStyle(scene);
initStage.setScene(scene);
initStage.setResizable(false);
initStage.titleProperty().bind(I18N.createStringBinding("title"));
initStage.show();
}
从错误提示来看,好像是读取FXML文件失败,但奇怪的是我在其他项目中用同样的方法读取了FXML文件,打包成EXE可执行文件后就正常了,我就是困惑。
我不知道为什么,但我后来创建了另一个 JavaFX 控制器 class,从旧控制器 class 复制了方法并删除了旧控制器 class,并且问题已解决。
我用JavaFX构建的项目在编译器中运行良好,但是当我将其打包为EXe可执行文件时却出错了。 运行打包EXE程序时提示的错误信息如下:
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(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2459)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
at cn.ambit.app.App.start(App.java:40)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater(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(WinApplication.java:174)
... 1 more
发生错误的函数:
@Override
public void start(Stage initStage) throws Exception {
FXMLLoader initFXMLLoader = new FXMLLoader(App.class.getResource("/view/initializationStage.fxml"));
AnchorPane anchorPane = initFXMLLoader.load(); // line 40
Scene scene = new Scene(anchorPane);
JMetroThemeManager.setSceneStyle(scene);
initStage.setScene(scene);
initStage.setResizable(false);
initStage.titleProperty().bind(I18N.createStringBinding("title"));
initStage.show();
}
从错误提示来看,好像是读取FXML文件失败,但奇怪的是我在其他项目中用同样的方法读取了FXML文件,打包成EXE可执行文件后就正常了,我就是困惑。
我不知道为什么,但我后来创建了另一个 JavaFX 控制器 class,从旧控制器 class 复制了方法并删除了旧控制器 class,并且问题已解决。