1

I have a problem with my .jar file. It work's perfect when I run it in IDEA, but when I build it in jar file, application ignore double click. I tried run it in cmd line and received next exceptions:

  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.

[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"

2 Answers2

1

It won't work as you cannot access files in JAR from filesystem (which is what File API do)

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! 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. You should use resources to access project specific material from JAR.

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")

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • Thanks for answer, but: What I've done: I created new fxml file with button witch stars my Interface.fxml, and it works. whhhhyyyyyyyy?????? –  Mar 04 '19 at 08:42
  • Because IDEA (nor Ecliplse nor NB) don't build JAR to run the application. It uses plain files most probably located in `classes` directory which are not packed into anything and exists on filesystem. – Antoniossss Mar 04 '19 at 08:44
  • Yes, but when added new fxml file with button witch stars my Interface.fxml, it works with jar too –  Mar 04 '19 at 08:46
  • Because autogenerated code is generated using resources not files like you do. – Antoniossss Mar 04 '19 at 08:50
0

Make sure to add all the required jar files to the exported jar file, when building/exporting your application. There is a description on who to do this: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project

Marvin Klar
  • 1,869
  • 3
  • 14
  • 32