I'm getting the following NoClassDefFoundError
, which is weird, because the class is already present in the library jar.
Exception in thread "main" java.lang.NoClassDefFoundError: abc/test/Test.java
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:795)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:382)
at java.net.URLClassLoader.access$100(URLClassLoader.java:75)
at java.net.URLClassLoader$1.run(URLClassLoader.java:294)
at java.net.URLClassLoader$1.run(URLClassLoader.java:288)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:287)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:795)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:144)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:382)
at java.net.URLClassLoader.access$100(URLClassLoader.java:75)
at java.net.URLClassLoader$1.run(URLClassLoader.java:294)
at java.net.URLClassLoader$1.run(URLClassLoader.java:288)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:287)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:432)
Caused by: java.lang.ClassNotFoundException: abc.test.Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:299)
at java.net.URLClassLoader$1.run(URLClassLoader.java:288)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:287)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 25 more
This looks like its not able to find the same class which is causing the exception.
I have also included the library path in ant build.xml
, which can be verified below.
<property name="deps" value="${lib}/abclib/abclib-test.jar"/>
<target name="dist" depends="compile">
<manifest file="${dist}/MANIFEST.MF">
<attribute name="Main-Class" value="xyz.test.TestConfiguration" />
<attribute name="Class-Path" value="${deps}"/>
</manifest>
<jar jarfile="${dist}/abc.jar" basedir="${build}/" manifest="${dist}/MANIFEST.MF" />
</target>
I'm lost, can someone at least guide me where should I look, or what I might be doing wrong?
Also, can someone throw a light, Exception
and Caused by
from the stacktrace. I'm not quite getting how are they two related.
There's a really good explanation of the difference between NoClassDefFoundError
and ClassNotFoundException
in another SO entry:
does not mean that the ... class is not in the CLASSPATH. Infact its quite the opposite. It means that the class ... was found by the ClassLoader however when trying to load the class, it ran into an error reading the class definition. This typically happens when the class in question has static blocks or members which use a Class that's not found by the ClassLoader. So to find the culprit, view the source of the class in question ... and look for code using static blocks or static members.
You need to look at the code for Test.java and figure out what it imports and make sure those classes are on the classpath. You could post the code of Test.java if you need help tracking the classes down.