getTimeStamp() not found in runnable jar, but is found otherwise - java

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.

Related

Issues with creating a JAR file with Eclipse

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.

JAVA jar file to exe error

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

build java project into executable

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.

Eclipse java lwjgl no lwjgl in java.library.path

I installed and putted lwjgl library and natives to /lib folder. On eclipse Java build path setted library location and native library location. When i try to run it on eclipse, it works, but when i export it as a runnable jar, it doesn't run, and throws error:
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:132)
at Main.start(Main.java:9)
at Main.main(Main.java:31)
Tried to set run properties VM argument to -Djava.library.path="lib/" but it doesn't work too.
P.S. Tried to put the native .dll's to same folder as the jar is and it works, but I want to .dll's to be in other folder.
Thanks!
Found an answer. You can do it with custom .bat file and put there -Djava.library.path="lib/", but mine solution is to programmaticaly do that with next line:
System.setProperty("org.lwjgl.librarypath",System.getProperty("user.dir") + "/lib/");
Have you tried using JarSplice? It is a free Java .jar packaging program found here:
Ninja Cave - JarSplice
Follow the instructions. All the documentation is on this site. Just make sure that the JAR you use for your program is just an eclipse JAR file, not a runnable jar. When you start up JarSplice, add the appropriate Jars, Natives, define your main class, and simply create a runnable JAR. No need to set up VM configurations, and also you can export to Windows.exe, and MacOSX. If all goes well, you should have a double-clickable runnable jar. Hope this helps. It's how I've packaged LWJGL games in the past :)

Java error using JARs, java.lang.NoClassDefFoundError: javax/mail/Store

I'm making a java application that uses Javamail, and it works great when I compile it. I want to make it into a jar file so it can be easily moved around and executed. The problem is I am getting this error when I try to run the jar from the cmd line
java -jar ActriveTray2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Store
at stockApp.init(stockApp.java:11)
at ActiveTray.main(ActiveTray.java:31)
Caused by: java.lang.ClassNotFoundException: javax.mail.Store
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)
Here's what's in my jar file
images/tray.gif
META-INF/MANIFEST.MF
ActiveTray.class
ActiveTray.java
config.class
config.java
GmailFetch.class
GmailFetch.java
stockApp$1.class
stockApp.class
stockApp.java
I think the issue is classpath, where the jar doesn't know where the javamail jar lives. My classpath is set correctly when I execute the code (java ActiveTray2) it works fine... help :(
you need to add the jars you depend on to the manifest file, and also add them to the jar you are creating. java -jar will ignore your environment's classpath, by design.
From the java docs:
-jar: When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
so, you can add a line to your manifest file like:
Class-Path: mail.jar
to your manifest file.
When you launch a runnable jar file in java, the classpath is ignored, both the environment variable and the command line classpath. You have to specify it inside the manifest file of your runnable jar file.
Here is some information from wikipedia :
You manifest has to include :
Main-Class: org.mypackage.HelloWorld
Class-Path: lib/supportLib.jar
<additional line feed and carriage return>
The class-path will list the location of the librairies you use relative to the location of your main runnable jar file.
Regards,
Stéphane
The required mail implementation jars should be present in your classpath.
Same problem i faced in my project. The reason is jar file missing or not locate in class path. Two steps to solve this issue.
First add JavaMail API 1.4.7 jar to the class path.
Then add the same jar to server library. In my application i used Apache tomcat 7. i put the jar in lib folder

Categories