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 :)
Related
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/
I built a javaFX artifact using IntelliJ. My first problem was in the Application Class box, where it didn't automatically detect my main class, or even suggest any classes as main class when I searched in the search box. I saw that it was a bug with IntelliJ, somewhere on StackOverflow, and I just manually entered my packageName.Main in the application class box.
I have two dependencies that I extracted into this output root. The output of building the artifact looks like this.
Then after rebuilding the project the JAR runs on my PC 100%, even if I move the JAR to another directory, it works 100%.
So I copied this JAR (Swansong.jar) to my other PC and when I double-clicked it, nothing happended. When I ran it in the cmd:
java -jar Swansong.jar I got this error:
Error: Could not find or load main class swansong.Main
Caused by: java.lang.ClassNotFoundException: swansong.Main
I read about manifest files but I can't find a manifest file anywhere in my project, but if I extract the JAR file the manifest file that was generated looks like this. Can anyone please help me, why does the JAR run on one PC but not on the other? And how can I fix this?
UPDATE:
This is the contents of my jar file and this is the contents of the swansong directory inside the jar file.
UPDATE 2:
I feel stupid. My main PC runs jdk8 and my other pc runs jdk11. And JavaFX is not included in the jdk11. So I think this is the problem, but not 100% sure yet. Will test and see. Are there any workarounds for this?
I hate to admit it, but the solution to the problem was staring me in the face all along, and I am truly embarrassed. I used Java 8 to develop the program. Target PC was using Java 11 and I never thought to check the JDK version, because I thought I was using JDK8 on both PCs.
JavaFX is included in JDK8, but not in JDK11. It should be added to a project as an external library when using newer JDK versions. I just used JDK8 for running the program and everything works 100%. Thanks for the answers and comments though, I learned a lot about manifests and classpaths trying to solve this problem, so the effort was not in vain!
Any executable jar file needs to have manifest file which points to the main class.
-JAR File
\---META-INF
\--MANIFEST.MF
In the MANIFEST.MF, you should introduce the main class as this:
Main-Class: com.mycompany.MainClass
Class-Path: .
com.mycompany.MainClass should be replaced with appropriate path (fully qualified name of your main class)
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
I seem to have a strange issue which is most likely to be caused by not understanding how the including of additional libraries in java work.
I wrote a program that uses jnetpcap.jar to work with pcap files. The application is running fine when I start it from eclipse and has also worked many times by exporting a runnable jar (copying required-libraries to sub-folder). It even worked on other computers.
As mentioned in jnetpcap doc, the computers running windows have put jnetpcap.dll into C:\Windows (according on every machine the x86 or x64 dll)
Anyhow, the following scenario is reproducable on my and other machines:
running the complete eclipse project works
running from cmd with java -jar pcapdump.jar works
double-click jar the gui etc. works - but the "main work" is not done, so no pcap file is used.
I don't see any errors in my logs.
Configuration in eclipse:
added an external user library. pointing to my local jnetpcap.jar and source-jar.
When exporting as runnable-jar with copying libs to sub-folders the jnetpcap.jar gets copied into a separate sub-folder. Like I did it many times before.
Anyhow the described problem exists today and I don't know what I am doing wrong or what may be wrong.
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.