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.
Related
How can i make an executable of my project in Java?
I tried to right click on my project and selected export .
the problem is that the exported jar file wont open when I execute it! Have I missed something? And is there a way to make an .exe executable from my project?
when I execute the jar file in cmd it says :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr
ary.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at JavaGame.Game.main(Game.java:34)
UnsatisfiedLinkError indicates that you're missing a native library (usually a .dll file on Windows, or .so file on Linux). You'll need to do one of the following:
Not recommended: Copy the native library to a location on the default java.library.path (on Windows, this includes C:\Windows\system32)
Not recommended: Copy the native library to a directory, then run your program with java -Djava.library.path=dir/containing/library -jar <jarfile>
Recommended: Bundle the DLL in your jarfile, then modify your code to extract the DLL to a temporary directory and load it using System.load or System.loadLibrary.
You can use either of the first two solutions above as a quick hack to get it working, but neither of those solutions is very good. The best solution from a deployment standpoint is #3 above.
In your case, you're using the Lightweight Java Game Library, or lwjgl as referenced in your UnsatisfiedLinkError. So you'll need to include any DLL(s) that come with lwjgl.
When you unzip lwjgl, you'll notice that it has a native directory with a subdirectory for each supported platform. Here is a listing of lwjgl's Windows DLLs:
To implement solution #3 above and make your executable jarfile cross-platform:
in your project/jarfile, create a separate directory for each platform
put all the native libraries for each platform in the appropriate directory (it may be helpful to put them in the same directory as some utility class that you'll later use to extract them)
when you export your program to a jarfile, make sure the native libraries are included
look up the platform/operating system (e.g., System.getProperty("os.name"))
in your Java code (probably in your main method or some utility method), create a temporary directory
for whatever platform you looked up in step 3, extract the appropriate native libraries into the directory you created in step 4 (hint: use Class.getResourceAsStream to get an InputStream, then use Files.copy to extract it to a file)
for each library you extract in step 5, call System.load("path/to/library_file")
See https://stackoverflow.com/a/1611367/44737 for a nice example including code.
You can either package everything in a jar manually using the jar command line tool or you can automate the process of packaging your jar using tools like Ant, Maven or Gradle.
Once you have your class files properly packaged in jar file, you can execute them by creating a script file appropriate for your operation system. For instance a batch file in windows or a bash file in Linux.
All you have to do is invoke the java command and provide your class path and the name of your application entry point.
#!/bin/bash
java -cp myApp.jar com.my.app.Main
And that's it. You execute your application by invoking that script.
Additionally, you can make arrangements to create an executable jar, by means of defining a MANIFEST file for you jar file. In that manifest file you can place a property Main-Class that indicates your application entry point and you can define another property called Class-Path which allows you to specify a list of other jars needed by your application.
See Running Jar-Packaged Software.
If you package your jar this way, some operating systems allows you to execute the application by simply double-clicking the jar.
But most probably, you still will need to create a script, just a bit different this time:
#!/bin/bash
java -jar myApp.jar
See the Java Tutorial: Packaging Applications in Jar Files.
Ultimately, if you really, really need to create an executable file, and if you're working on windows, you may consider a tool like WinRun4j.
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 create a new jar file. when i run the jar using
java -jar UpdateAvailable.jar com.dao.mysql.UpdateAvailable
I got the following exception.
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jettison/json/JSONException
Caused by: java.lang.ClassNotFoundException: org.codehaus.jettison.json.JSONException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
But I copied all the supporting jars inside the UpdateAvailable.jar. Now what my requirement is run the jar file with out specifying supporting jars, like
java -jar UpdateAvailable.jar com.dao.mysql.UpdateAvailable
Here are some points to remember while you are working with JAR files and ClassPath: -
For making your JVM find class, your classpath should be set till the directory containing the class. In this case you have JAR.
So, you need to give the path till your Jar File Name
Now, since you have your Jar files inside your currently running Jar file, you can't set your classpath till the folder inside a Jar, so basically you won't be able to set classpath for inner Jar Files..
So, clearly JVM won't be able to see classes inside your inner Jar..
So, make sure that your required JAR files are outside of all the JAR files (I mean to say - avoid Nested JAR Files)..
I'm not sure how you are packaging your jar file, but it would sound like you need something like One-Jar to help you package your file and all your supporting libraries into a single jar. One-Jar comes with it's own classloader that allows it to load all the included jars in your executable jar file.
Configuration is fairly straight forward and easy to use. If you are using Maven, you can use the one-jar maven plugin to help you configure which libs you want included.
There are also other similar packages you can use instead of One-Jar, such as JarJar and ProGuard. Also take a quick look at this SO question.
In executable jar couldn't reads any supporting jar files inside a jar. So keep all supporting jars in a folder and place the executable jar in the same directory. And add "Class-Path" as "Supporting jar files separate with space" in "MANIFEST.MF" File. Now run the jar as
java -jar UpdateAvailable.jar com.dao.mysql.UpdateAvailable
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.