可能的原因的NoClassDefFoundError [英] Possible reasons for NoClassDefFoundError

查看:225
本文介绍了可能的原因的NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下的NoClassDefFoundError ,这是奇怪,因为该类已经是present库中的罐子。

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

这看起来像它不能找到,这是造成异常的同一类。
我也包括在蚂蚁的build.xml ,可以确认以下库路径。

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 light, "Exception" and "Caused by". I'm not quite getting how are they two related.

推荐答案

有区别的的NoClassDefFoundError 之间的一个很好的解释和的ClassNotFoundException 在另一个<一个href=\"http://stackoverflow.com/questions/1457863/what-is-the-difference-between-noclassdeffounderror-and-classnotfoundexception\">SO进入:

There's a really good explanation of the difference between NoClassDefFoundError and ClassNotFoundException in another SO entry:

并不意味着...类不在CLASSPATH中。逸岸它的完全相反。这意味着,类...被尝试加载类然而,当的ClassLoader找到,它遇到了一个错误读取类定义。这通常发生在有问题的类有静态块或使用不是由ClassLoader的发现了一个类成员。因此,要找到罪魁祸首,查看相关类的源...和使用静态块或静态成员寻找code。

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.

您需要看code为Test.java,弄清它进口,并确保这些类的类路径上。如果您需要帮助跟踪类下跌,你可以张贴Test.java的code。

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.

这篇关于可能的原因的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆