I'm getting the NoClassDefFoundError after executing my project's JAR file.
Debugging with Eclipse works fine, but I get this error whenever I use the windows command java -jar myproject.jar
since I installed JDK 1.7.
It was working fine using Java 1.6.
Here's the error log :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layout
at program.Main.main(Main.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout
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)
... 1 more
I googled about that but couldn't find the right solution.
What I already did : -uninstall Java 1.7, install 1.6 instead -check the classpath -try on an other computer (after uninstalling Java 1.7 from it) -create an empty project with one reference to the log4j library => same problem
And here's the classpath file :
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con"path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="lib/RXTXcomm.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Do you have any idea what else I should do?
Thanks,
Nils
EDIT : if I export the project as an "runnable JAR" instead of a simple "JAR", the program starts but fail to use another library I'm using (RxtxComm). Here's the log I get:
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
EDIT2: I finally resolved the last problem by putting the rxtxSerial.dll in the Windows/system32 folder. But still, I don't understand why it doesn't work anymore if I export my project as a JAR file and why I need to use the dll file now.