IntelliJ Exe build not working as I expected - java

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
Application Class
Title
Vendor
Version
Native Bundle (exe)
Enable Signing with Self Signed Key.
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,
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.
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?

There are a couple of routes to export Javafx. I am assuming that you are exporting the file into a jar file first and compile it into an executable file.
The easiest way is to set JDK 8 on your project: File -> Project Structure -> Project -> Project SDK, because Oracle has removed Javafx from its compiler in the more recent versions of JDK. You can download JDK 8 from here. If you choose to use JDK 8, make sure that on your IntellijIdea exporting page you export it as a Jar file, not a Javafx file.
Use Gradle to build your Jar. Gradle will help you automatically manage your dependencies, and I think it's quite easy to set up in IntellijIdea - you can set it on the page where you initiate your project.
Regarding actually compiling it into a exe, I think this StackOverflow post would be quite useful(you might have already come across this post).
Exporting java projects is definitely quite cumbersome. Good luck!

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/

Related

Generating executable file in IntelliJ for Windows

I used to work on an IntelliJ project that was started before I started working on it. This project had a configuration that allowed me to generate an EXE file that could easily be sent to windows users.
It would generate a massive EXE file bundled with all the needed JARs of the application, and upon running it the first time, it would silently "install" itself into the AppData folder, as if it were a regular windows setup file, even though the user would not even notice it doing that installation.
I am trying to configure a project in IntelliJ to do the exact same thing, but first I have not been able to output the exe file by selecting "exe" as the Java FX native bundle type. It just generates a .jnlp and .jar file. When I select "all", as per some other post here in stackoverflow, it generates an exe file, but only with a few kb in size, which does not contain any of the .jar files that should be part of it. Moreover, when I try to open it, it just crashes saying the main class was not found.
Am I missing some setting for building the project? I am using IntelliJ 2018.3.2
Here are some screenshots:
I have been able to get past this error, after changing the verbosity of the compilation and going through the logs.
There was a log message which helped fixing this:
The process complained about the Inno Setup Compiler missing, which was right. Makes me wonder why IntelliJ would have that feature built in if it depends on external tools but does not notify the user clearly of this.
Detected [iscc.exe] version 0.0 but version 5.0 is required.
After going to the Inno Setup site, downloading and installing the tool, I was able to get the executable to be generated.
Now I am struggling with another error, which is the executable complaining about the main class referenced in the Artifact not being found, but at least I have moved past the first problem! Going to tackle this one now...
The best solution for this is using exe generator software.
There is plenty of exe generators out there.
EXE4J is the most simple & easy tool to use.
In EXE4J,
You can upload your main jar file and select the main class.
I think this will be solved your problem.
This may be due to you`ve extracted Jars to your output root, while you neet to Put it(you can check difference by deleting everything from your output root in Output Layout screen and then just right click on jar on the right side, you will see two options here, try another one

Java 10 executable won't execute after installation

I have a weird problem - I have a javafx program that I compile and package using maven (for windows I use Inno setup to create a setup package). After upgrading from Java 8 to Java 10 (updating the plugins in the pom.xml file and updating the configuration) - iv'e gotten to a point where the build completes successfully.
The problem is that after installing the package on windows - the exe file that's starts the program won't run properly. It starts for a split second and then stops.
The weird part : if I try to run the same exe from the target\bundle folder (the folder where maven prepares the files for the packager) - it runs fine!
the two folders - target\bundle and Programs files(x86)/vendor/appname are identical (files and the configuration file content).
I checked the permissions of the exe under Programs files(x86)/vendor/appname and they seem fine.
I'm testing on a windows 8.1 machine (an on others which display the same behavior, which leads me to believe this a real problem and not a mis configuration of my testing machine).
the same script is used for creating an installation package for MAC OSX and everything works fine on OSX so it's not a problem with the code.
Any ideas as to what's causing this and how to fix it?
Additional info :
This has only started to happen since moving to Java 10. Java 8 and 9 work perfectly.
My app does not write to any files in the program files installation folder. configuration and log files are written to in the %user%/AppData folder only.
I found the problem by creating a working setup package manually with the Inno setup wizard and then comparing it to the one I had that was not.
After doing this I compared the iss file (Inno config file) that the wizard created with the only that wasn't working. It turned out that the bouncy castle jar files created a problem. The iss script from the previous version copied them to the lib/ext folder and that created a duplicate classpath problem for the java class resolver as there were two copies of the jar.
This is not needed in Java 9 and Java 10. Removing the manual addition of the bouncy castle jars from the iss file fixed the problem.
Hope this helps someone in the future :)

JFreeChart Java JAR not running on a different machine

I have created an application using the JFreeChart library for use on another machine.
Previously I have developed applications with JFreeChart (using the same libraries) which has worked fine on other machines. The only difference is this machine is running Vista.
Please see below for the run-time exception I am getting:
The class that cannot be found, however, is located in the highlighted jar in the below image showing my imported libraries for the JAR. I have also established that this JAR is included in the manifest for the application. See below image:
So I very much need this to work and have no idea where to look next - or what is causing this problem!
Development machine Java version:
1.7.0_45
Target machine Java version:
1.7.0_45
Thanks in advance.
Check the Class-Path attribute in your JAR's manifest, which should contain entries like this:
Class-Path: lib/jfreechart-1.0.17.jar lib/jcommon-1.0.21.jar …
Also, examine dist/README.TXT in your NetBeans project folder, which should say something like this regarding libraries required by your project:
To run the project from the command line, go to the dist folder and
type the following:
java -jar "CISOnlineMonitor.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
This has nothing to do with os i belive.You dont have all the necessery libs within your jar.Try to open a jar and see if you have them in.Fact that you are able to run it on your maschine only proves that.Make executable jar with eclipse or whathever you use.And when it ask you for libs check -Extract required libraries into generated Jar.
if you dont know how to get to that point
File>Export>Java>Runnable Jar File> Runnable JAR File Specification.
Also right click on your project and check Your build path.
RightClick project>Properties>Java Build Path>Libraries
Make sure you have everything correct
EDIT-
As i see you use NetBeans im not sure exactly how to find all this there.Bud it will be very similiar.

Why javaFX application jar runs on jdk but not on jre?

I've my JavaFX app that calls some JNI code, uses a preloader jar and is compiled using jdk 1.7.
Now when I run jar on another computer with JRE7, by:
Double clicking jar: it starts but cannot load the JNI code containing libraries and therefore gets stuck.
Running jar via terminal using "java -jar ": App runs completely normal!
Now if I install jdk on this machine,
it runs fine even with double click!
Can somebody tell me what is difference in these 3 cases?
Try to add logging to your program, so that you can figure out why your JAR file doesn't execute properly.
You should look into if your manifest file is correct - there is a classpath in there you might want to take a look at.
This may have something to do with the fact that JavaFX is not fully released with Java 1.7, but included more as a developer preview.
Also, JavaFX packaging and deployment is a little different than standard Java. There is a new utility called 'javafxpackager' that should be used when packaging JavaFX applications. Check out the documentation here: http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm

Simple swing application. The jar file runs on my computer, but not others

This is my first question, so apologies for any mistakes. I'll try and give all the info I can. Basically I've written a simple swing application which just loads in image into a JPanel and displays it. I'm using Netbeans 7.1 and I have the latest version of the Java SDK.
Anyway, I've used the "Build" feature in NetBeans 7.1 to deploy my application into a Jar file. When I double click the Jar File on my PC, it runs without a problem. However when I put it on other computers (Tested on 2 others so far, both with the most current JRE) it fails to open, citing the following error:
could not find the main class: swong.Startup. Program will exit
swong is my package name, and Startup is the location of my main method. I have checked the manifest file which is created with Netbeans' build, and it[the manifest] does indeed contain the location of my main method class.
From searching, I've come across similar issues in which the classpath is set wrongly, but I don't understand how this could cause my particular error.
If someone could help me, I would be over the moon. I've been studying java for a year or so, and I've got a good handle down, but I've NEVER been able to make a Jar that runs on a computer which wasn't my own. So, 10 points and thanks in advance.
xo.
EDIT: Thank you for the responses. I'm doing shift work and swamped, but I will test and poke with these responses tomorrow and provide more information. Thanks again. xo
I had d same problem while distributing my app. There is 1 solution that you create a batch file with 'java -jar AppName.jar' and asking user to double click on this batch file to execute your app. What i did was to provide a JRE installation exe(eg: jre_1.7.0) with your app.
Now create a Batch file (install.bat) in which write following commands
jre_1.7.0 -> this will install jre on user's pc
set path="C\Program Files\Java\jre_1.7.0\bin"
java -jar yourAppName.jar
Why i installed JRE because different people have different JRE versions installed. So this makes it difficult to set path to the installed JRE's bin folder & calling the 'java -jar' command. Hence as you know which folders your JRE installation will create hence it is easy to set path and execute your jar file with 'java-jar' command.
Check that your jar file has the following structure (at least)
jarfile.jar
|---------- swong
|---------- Startup.class
|---------- META-INF
|---------- MANIFEST.MF
It seems like the class "Startup" is missing. Maybe your jar only contains the .java files, not the compiled classes.
This error message can be a mistakable java7 error, when you try to start java7 compiled classes with a different Java Runtime Environment then java7. Have you validated, that your .jar is started within a Java7 environment on those other test machines? Sometimes it happens, that you have installed different versions of JREs and you might not be sure which one is actually started.
To check which enviroment is used, you can check in your registry for the following value:
HKEY_CLASSES_ROOT\jarfile\shell\open\command
this should point to your latest JRE. Or if you'd like to stay compatible to java6 as well, define the appropiate compile level in your build environment.

Categories