When I try to make my jar file into an exe file, when I run it I get an error. My java file while running in Eclipse works great.
Error occurred when starting the application:
I have used both exe4j and Launch4j.
exe4j gives this error:
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at EasyExpress.<init>(EasyExpress.java:61)
at EasyExpress.main(EasyExpress.java:162)
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.exe4j.runtime.LauncherEngine.launch(Unknown Source)
at com.exe4j.runtime.WinLauncher.main(Unknown Source)
The immediate cause is most likely that you have used Class.getResource (or similar) to get the image from your application resource collection. When that fails, it returns a null. You have then passed that null to ImageIO.read. Hence, the exception you are seeing.
The problem is likely to be one of the following:
The resource is not in or available to the (ultimate) executable.
The resource is there, but your application is using the wrong path.
Here's what I'd do.
Generate an executable JAR for the application using Eclipse.
Run that JAR ... outside of Eclipse (!) ... to see if you get the same problem.
If yes, then solve the problem in the context of the executable JAR. It will be easier, and is highly likely that you will fix the problem for the generated exe file as well.
If no, then investigate how the exe4j tool handles resources and resource loading. (My brief read of the exe4j documentation did not highlight any obvious gotchas ...)
If you only want to run it outside eclipse then you could make a JAR file. In eclipse click File > Export JAR > Select Java JAR File > select project > select destination to save to. Done
Related
I have to extract a runnable jar file from an Eclipse project. I know that choosing Package required libraries into generated JAR makes the jar file slower than choosing Extract required libraries into generated JAR, but the problem is that if I extract the libraries, rather than package them, the application doesn't start because of the following error:
Catched FileNotFoundException: C:\Users\rober\Desktop\palbo-natives-windows-amd64.jar (The system cannot find the file specified), while TempJarCache.bootstrapNativeLib() of jar:file:/C:/Users/rober/Desktop/palbo-natives-windows-amd64.jar!/ (file:/C:/Users/rober/Desktop/ + palbo-natives-windows-amd64.jar)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:454)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$2.run(Platform.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
at org.jzy3d.global.Settings.<init>(Settings.java:12)
at org.jzy3d.global.Settings.getInstance(Settings.java:21)
at org.jzy3d.chart.Chart.<init>(Chart.java:59)
Of course, all the required libraries have been added to the Eclipse project and thus the application perfectly works if launched in Eclipse.
Is there a way to avoid this issue? In other words, is there a way to make my jar finding all the required libraries even if I choose the option Extract required libraries into generated JAR or Copy required libraries into a sub-folder next to the generated JAR?
Additional info:
even if I choose the option Package required libraries into generated JAR, I need to have some .dll files (e.g. gluegen-rt.dll, jogl.dll, jogl_awt.dll, jogl_cg.dll) in the same folder of the runnable jar files in order to make it opens correctly. Moreover, the application takes forever to be initialized.
Summary:
Extract required libraries into generated JAR or Copy required libraries into a sub-folder next to the generated JAR: the application cannot be opened because of the above posted Exception.
Package required libraries into generated JAR: noteworthy performance issue.
I have written a java program to convert input xml file into some other xml file. While doing this I am using excel file and for accessing xml file I used apache-poi libraries.
When I run my program in eclipse it works fine and gives required results. Now I export the project in jar file and I selected my main class while exporting into jar. But when I run the jar file, I am getting following exception:
D:\>java -jar EDR_to_DER_with_excel.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com.unisys.xml.TestExcel. Program will exit.
The error is related to libraries that I am using. But I don't know why it's coming, because I am able to run the program in eclipse. Is the library class available in jar file> If not how can I give it to the jar while exporting?
It appears that the Apache POI Libraries are not in the classpath
Add the location of the libraries to PATH variable of your system (Assuming windows based on D:\ drive in question).
Export project do not included the external jars by default.
You have to add the third party lib to the classpath:
java -cp <lips> -jar EDR_to_DER_with_excel.jar
I got the solution. I followed simple approach.
-> Right click on project
-> Export
-> as Runnable jar
-> select radio button "Package required libraries into generated jar"
-> finish
This approach worked for me :)
I got the answer of the query in this case the jar files are missing in the program .Please check there are added from proper path.
This worked for me
I've created a SWT application using eclipse. In the application I make use of Images with in the project. Now I build the jar file and run it in the command line I get the following error:
Caused by: java.io.FileNotFoundException: Images\Back.png (The system cannot fin
d the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at org.eclipse.swt.internal.Compatibility.newFileInputStream(Unknown Sou
rce)
Now I can see that the program cant read my Image but I would like to ask how to I include the Images in the jar file for everything to run smoothly.
Right click on your project, choose export.
Export -> Java -> Jar file
Choose the resources you would like to export, then click Finish.
If you need a runnable jar, just make sure the files are part of your project. For example make a folder called "Images". Then exporting a Runnable Jar should work.
That will get you the Images into your Jar file. Once it's there you will need to retrieve it using the method "getResourceAsStream". If you need help with that there are numerous good answers, here is one, Getting images from a .jar file.
I've have trouble deploying an application that runs fine within eclipse, but generates the following error when creating a runnable jar (using the option: extract required libraries into generated JAR):
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NoSuchMethodError: org.apache.log4j.spi.LoggingEvent.getTimeStamp()J)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
I'm using log4j-1.2.16.jar and it's included in the generated jar.
I'm not sure where to troubleshoot, I've tried to find other (older) instances of org.apache.log4j.spi.LoggingEvent in other jars that are included, but so far I did not find any.
It says, that there is not method org.apache.log4j.spi.LoggingEvent.getTimeStamp()
Find again your classes, that are on class path and you should find class org.apache.log4j.spi.LoggingEvent twice. One with method one without method.
I'm using log4j-1.2.16.jar and it's included in the generated jar.
Java class loaders are not designed to deal with a Jar inside a Jar. It is possible to put the resources (classes etc.) of a Jar into another Jar (I think using a tool called 'FatJar' in Eclipse), but that might break the EULA.
The usual way to include a Jar on the run-time class path of an application is to add a manifest file that specifies a relative path to the Jar.
Hi I want to create an exe file for my java app.
I tried with some third party softwares JEXECreator, successfully created the exe file and its working fine in my system, when I tried with another machine, it’s not working. I got the following error
* The error occurred while running the application. The exit code is 0x10000223.
* Contact the vendor of the application for troubleshooting.
java.lang.ClassNotFoundException: com.sample.SampleMain
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.ucware.JEXEClassLoader.run(Unknown Source)
at com.ucware.JEXEClassLoader.main(Unknown Source)
**************************************
I know there is something wrong with the classpath which I set.
Actually I want to create the exe file myself without using any third party software.
I found the steps in lot of sites
Created the manifest file named Sample.mft with following contents
Manifest-Version: 1.0
Main-Class:
Class-path:
In this I have some doubts,
How the Main-Class should be added, with the full package name (com.sample.SampleMain) or the class name alone (SampleMain) or with the extension (SampleMain.class)
How the class-path should be added, I have 4 java classes and 2 jars in my project. How to add all these in the class path, and do I need to add the java jdk in classpath.
Where the manifest file should be saved
What should be the manifest file extension (mf or mft)
In command prompt from which directory I should create the exe file (from my project folder or src folder or the folder which contains all the java classes)
What’s the syntax should be used while creating jar in command prompt
(jar cmf Sample.mf Sample.jar Sample1.class Sample2.class Sample3.class Sample4.class jar1.jar jar2.jar) like this or (jar cvfm Sample.jar sample.mf *.class)
When I did something like this I am getting a jar instead of exe file, When I run the jar in command prompt using "java -jar sample.jar" then I am getting class not found exception".
Actually how to create an exe file instead of jar file, that means just by double clicking that exe file, should run my app in any machine.
Can anyone help me to do this?
Thanks in advance.
I use the Ant tool under Eclipse IDE to work with InnoSetup and Launch4J to create the EXE and its installer which it also manages the classpath...
A guide? You can refer to:
http://www.eteks.com/tips/tipCreationExe.html (in French)
Can't speak for JEXECreator, but I can recommend JSmooth (http://jsmooth.sourceforge.net/). I've successfully used it for several projects (e.g. this SWT based Java app).
Personally, I like JSmooth. That is just wrapping. This means it is still a Java application. When executing the exe, it will unpack the jar to a temporary folder and then execute it with javaw -jar ...
A second option is gcj. But that is absolutely a bad choice. That doesn't wrap the jar in an exe, but it really compiles it to native system code. But this slows down your application very much. You can check some results of my timing on this topic.
I had some positive experience with Excelsior JET. Unlike gcj it actually works and execution times are faster than that of an executed .jar file. The downside is that it's not for free.
Well I will recommend you to create one bash file instead of doing complex things and by double clicking on it you can run your application.Yeah but you cant change its icon but there are many free tools are available by using which you can easily convert bash file to exe.
To create an exe file, I use launch4j. Launch4j converts the jar file into exe file and if I wanna pack it for the installer, I use InnoSetup. For me, that exe created by launch4j works on pcs.