简体   繁体   English

可执行的 .jar 文件不运行

[英]Executable .jar file doesn't run

I have a problem with my .jar file.我的 .jar 文件有问题。 It work's perfect when I run it in IDEA, but when I build it in jar file, application ignore double click.当我在 IDEA 中运行它时它工作得很好,但是当我在 jar 文件中构建它时,应用程序忽略双击。 I tried run it in cmd line and received next exceptions:我尝试在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

I import to the project one library, when it worked in java 1.8 only, jar application hes been worked, but when I updated library for all java version, import to project, and run it, received this Stack Trace.我将一个库导入到项目中,当它仅在 java 1.8 中工作时,jar 应用程序已经工作,但是当我更新所有 java 版本的库,导入到项目并运行它时,收到了这个堆栈跟踪。

[Edit] Changes in lib: [编辑] 库中的更改:

 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());

    });

}

Was without "com.intenselab.jlabframework"没有"com.intenselab.jlabframework"

It won't work as you cannot access files in JAR from filesystem (which is what File API do)它不起作用,因为您无法从文件系统访问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文件:/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%20(CODE)/out/artifacts/ApplicationExampleForClients_V_1_0_jar/ApplicationExampleForClients.罐子!/Interface.fxml

ApplicationExampleForClients%20V_1.0.jar! says that you want to access file that is inside JAR, and that will not work as your filesystem has no direct access to it.说你想访问 JAR 中的文件,这将不起作用,因为你的文件系统无法直接访问它。 You should use resources to access project specific material from JAR.您应该使用资源从 JAR 访问项目特定材料。

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

so you will end up with something similar to所以你最终会得到类似的东西

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

Make sure to add all the required jar files to the exported jar file, when building/exporting your application.在构建/导出应用程序时,确保将所有必需的 jar 文件添加到导出的 jar 文件中。 There is a description on who to do this: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project有关于谁来执行此操作的说明: 将外部 jars (lib/*.jar) 添加到 IntelliJ IDEA 项目的正确方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM