gpt4 book ai didi

java - 可执行的 .jar 文件无法运行

转载 作者:行者123 更新时间:2023-11-30 05:45:13 26 4
gpt4 key购买 nike

我的 .jar 文件有问题。当我在 IDEA 中运行它时它工作得很好,但是当我在 jar 文件中构建它时,应用程序忽略双击。我尝试在 cmd 行中运行它并收到下一个异常:

  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$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
file:/C:/Users/__it/Desktop/Ilab%20API%20UI%20+%20CODE%20v%202.0/ApplicationExampleForClients%20V_1.0%20(CODE)/out/artifacts/ApplicationExampleForClients_V_1_0_jar/ApplicationExampleForClients%20V_1.0.jar!/Interface.fxml

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2543)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
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 Main.start(Main.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
... 1 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[56,1]
Message: Stream closed
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
at javax.xml.stream.util.StreamReaderDelegate.next(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2513)
... 17 more
Exception running application Main

我向项目导入了一个库,当它仅在 java 1.8 中工作时,jar 应用程序已工作,但是当我更新所有 java 版本的库、导入到项目并运行它时,收到了此堆栈跟踪。

[编辑]库中的更改:

 private static void LoadPlatformPacketTypesFromAssembly() {

Reflections reflections = new Reflections("com.intenselab.jlabframework");

Set < Class < ? extends Object>> allProtocolMessages =reflections.getTypesAnnotatedWith(IntenseLabPacket.class);

allProtocolMessages.forEach(aClass -> {
crc32.reset();
crc32.update(aClass.getSimpleName().getBytes());
messageTypesMap.put(aClass, (int) crc32.getValue());

});

}

没有“com.intenselab.jlabframework”

最佳答案

它不会工作,因为您无法从文件系统访问 JAR 中的文件(这是文件 API 的作用)

File:/C:/Users/__it/Desktop/Ilab%20API%20UI%20+%20CODE%20v%202.0/ApplicationExampleForClients%20V_1.0%20(CODE)/out/artifacts/ApplicationExampleForClients_V_1_0_jar/ApplicationExampleForClients%20V_1.0.jar!/Interface.fxml

ApplicationExampleForClients%20V_1.0.jar! 表示您想要访问 JAR 内的文件,但这将不起作用,因为您的文件系统无法直接访问它。您应该使用资源从 JAR 访问项目特定 Material 。

https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html#class

所以你最终会得到类似的东西

InputStream in=SomeClass.class.getResourceAsStream("Interface.fxml")

关于java - 可执行的 .jar 文件无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54977873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com