I created a runnable .jar file from a project I built in Eclipse Juno. The project uses the JRE7 and JavaFX libraries, which I added to the build path.
Build Path Settings
The .jar file executes successfully on Windows 7 machines. However, when I try to run the .jar file on a WindowsXP machine, it fails with the following linking error:
Error on WindowsXP
The error reads:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: com.sun.glass.ui.win.WinApplication._invokeLater(Ljava/lang/Runnable;)V
at com.sun.glass.ui.win.WinApplication._invokeLater(Native Method)
at com.sun.glass.ui.Application.invokeLater(Application.java:338)
at com.sun.javafx.tk.quantum.QuantumToolkit.defer(QuantumToolkit.java:620)
The error occurs just as the program tries to load a class that uses JavaFX, The WindowsXP machine has Java Version 7 Update 40 which comes with JavaFX, so I can't figure out why it would fail.
Could this be a 32-bit vs. 64-bit problem?
Also, on the build path settings, I wonder if I'm including the right JavaFX jar file. I have two to choose from and I'm not exactly sure which one to include. I assume it's the second one because it's part of the JRE.
C:\Program Files\Java\jdk1.7.0_25\jre\lib\jfxtr.jar
C:\Program Files (x86)\Java\jre7\lib\jfxtr.jar
Thanks
1. JavaFX is embedded into JRE, but it is the separate library still now. So, if you use the JavaFX classes in your project, JVM should "know" about that. Your *.jar file should contain info about jfxrt.jar. How to do that?
2. JRE folder used for running the apps, such as *.jar files. JDK/JRE folder used when you developing your apps from IDE. So, you should use the C:\Program Files\Java\jdk1.7.0_25\jre\lib\ path for your project build path' libs.
As far as I know, there is no way to run JavaFX applications on Windows XP.
Despite all of my efforts, I couldn't get the .jar file to execute in Windows XP when I created it in Eclipse. But I could get it to work when the project was exported out of NetBeans. The trick was: I created a new "JavaFX in Swing Application" in NetBeans. That way, the IDE imported all of the necessary libraries for JavaFX. I copied all of my .java files from Eclipse into the new NetBeans project and it worked. Happy with NetBeans!
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 am using Eclipse 2020.03 and Java JDK 13.
I downloaded the appropriate JARs from the JavaFx download site.
When I run my project in Eclipse, there are no errors.
However, when I export the JAR and run it, the program encounters a runtime error that reads
No toolkit found
Here is what my JAR looks like when I change the extension to a .zip and open it:
Clearly, all of the required JavaFX library JARs are in there.
I have also tried using the export mode where Eclipse extracts the library JAR source code into the exported JAR but the same error occurs.
What am I doing wrong?
Edit: I am not open to using Maven.
I'm in the process of creating a fairly extensive desktop application using SWT. To generate an executable jar file I use maven-shade-plugin in version 2.1. After generating a file, typical double-clicking does not work (the system tries to open a few seconds and stops). Calling from the console
java -jar pakiet.jar
works very well.
Previously, I created a project with SWING with using the same plugin and double click worked without a problem. Is the problem may be to use SWT?
Java version 1.7.0_25
OS Windows 7 Professional x64
You can create a *.bat file with the following content:
start javaw -jar pakiet.jar
I've been using launch4j my my SWT applications, works really well. You can even bundle the jre to avoid any dependencies on the target machine. Supports a splash screen, icon for the exe, you can enforce single instance of the exe, min/max jre versions, graceful error message if jre not supplied etc etc.
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.
I tried to configure NetBeans(7.2) project to use Tess4J library.
Unfortunately all I get is runtime error:
Exception in thread "main"
java.lang.NoClassDefFoundError:
com/sun/media/imageio/plugins/tiff/TIFFImageWriteParam
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:166)
After some time of testing and trying I made a simple Tess4J project in Eclipse and everything is working fine but I don't want to convert whole my project to eclipse.
Both projects are configured the same way, yet NetBeans is refusing to work for some reason.
I've found one possible solution on StackOverflow to put libtesseract302.dll, liblept168.dll and tessdata in jdk/bin folder instead of project folder but I don't have administrator rights on the machine so that is out of the question.
Is there other way to make Tess4J work in NetBeans?
I also encountered the same issue under a windows version of tomcat.
Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/tess4j/Tesseract
and also
Unable to load library 'libtesseract302' problem (Tesseract is a 32-bit app).
I solved it by adding liblept168.dll and libtesseract302.dll to C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.37\bin (emplacement of the binaries of tomcat) and by linking the jar or the source code provided by Tess4j to my project.
Anyway, under Linux, everything went fine only by referencing the Tess4j project (and with Leptonica installed and data file in the right place)
Hope this helps, enjoy ;)
Tess4J is itself a NetBeans project. You would only need to open the project, expend the Test Packages, and execute the included unit tests -- no need to copy files anywhere.