Jar文件将无法运行后生成的神器 - JavaFX的
问题描述:
我有一个JavaFX项目包含FXML文件及其控制器和主类Jar文件将无法运行后生成的神器 - JavaFX的
程序完美的作品在IDE“的IntelliJ” 但是当我尝试制作工件并构建它时,jar文件就不会运行“当然安装了JRE”
我尝试了很多方法来构建工件,所以是否有构建jar文件的特定方法FXML文件?
堆栈跟踪异常
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at sample.Main.start(Main.java:20)
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 sample.Main
主类含有这种 “FXML装载机”
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
Parent root = null;
try {
root = FXMLLoader.load(getClass().getResource("/Sample/MainLayout.fxml"));
primaryStage.setTitle("Estimated Download Time");
primaryStage.setScene(new Scene(root, 764, 600));
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("Logo.png")));
primaryStage.resizableProperty().setValue(Boolean.FALSE);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {launch(args);}
}
答
我解决了从FXML装载机刚刚删除软件包名称问题
代替root = FXMLLoader.load(getClass().getResource("/Sample/MainLayout.fxml"));
我删除了包名“样本”,所以它成了这个
root = FXMLLoader.load(getClass().getResource("MainLayout.fxml"));
“的jar文件就不会跑”。究竟发生了什么?你有例外吗?如果没有,您是否尝试过从命令行运行jar文件来查看它是否以这种方式生成堆栈跟踪? –
我实际上得到java.lang.reflect.InvocationTargetException 例外在应用程序启动方法 但程序完美地在IDE上运行! – AhmadMujahid
因此,在问题中发布完整的堆栈跟踪。 FXML文件的路径可能不正确,或者FXML文件未被部署到jar文件。 –