Skip to content
Advertisement

IntelliJ Exe build not working as I expected

I am working on a JavaFX Application, which is a conferencing application. The application is running fine with IDEA. But my target is to build an exe from my application which would run standalone. I have configured an Artifact to build exe where I set the values for

  1. Application Class
  2. Title
  3. Vendor
  4. Version
  5. Native Bundle (exe)
  6. Enable Signing with Self Signed Key.
  7. Build Output Level (Default).

With this, I can successfully build the exe file. When I install this exe, it doesn’t run. My application has some dependency on other java libraries, which I have included in Output Root as Extracted. I have found that,

  1. When I run the installed application it simply does nothing and simply exits without error. I haver tried to the run exe from cmd as well, but same here.
  2. When I try to run the jar file of my application it it runs successfully.

though I have added these two lines in the MANIFEST file I am using, Manifest-Version: 1.0 Main-Class: sample.Main

I have tried https://www.jetbrains.com/help/idea/packaging-javafx-applications.html https://intellij-support.jetbrains.com/hc/en-us/requests/3231012?page=1 and many other solutions from internet. But nothing helped me in my case.

How can I debug this exe file or my project to successfully build an exe?

Advertisement

Answer

Thanks you guys. I have solved the problem.

My problem was, I was using

Platform.runLater(() -> {
    //some code here
});

Before launch(args); was called in the main Method. Which is fine if I run the program from IDEA (In my case it was IntelliJ) or if I run the program using java -jar MyJar.jar from command prompt. But it doesn’t work when I run it from exe (An exception occurs in this case

java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at javafx.application.Platform.runLater(Platform.java:83)

).

How To Debug

I had to put my whole code of main method inside a try catch block, and had to write the exception in a file or print the exception in the console.

Solution

If I put PlatformImpl.startup(() -> {}); and change my code to

PlatformImpl.startup(() -> {});
Platform.runLater(() -> {
    //some code here
});

then it works.

thanks to

https://staticfinal.blog/2015/04/04/javafx-toolkit-not-initialized-solved/

Advertisement