仍未找到buildpath-jar中的类

时间:2022-02-28 10:22:16

I'm developing a eclipse plugin rcp and I'm running into a NoClassDefFoundError

我正在开发一个eclipse插件rcp,我遇到了NoClassDefFoundError

Exception in thread "Thread-7" java.lang.NoClassDefFoundError: org/jdom/input/SAXBuilder  
    at org.geonames.WebService.search(WebService.java:783)  
    at geo.GeocoderGeonames$SearchThread.run(GeocoderGeonames.java:119)  
Caused by: java.lang.ClassNotFoundException: org.jdom.input.SAXBuilder  
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)  
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)  
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)  
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)  
    at java.lang.ClassLoader.loadClass(Unknown Source)  
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)  
    ... 2 more

The class that supposedly cannot be found is in a jar that I have added to the buildpath. I don't get any compile error etc only this exception when the running application enters the code where this class is needed...

据说无法找到的类是在我添加到构建路径的jar中。当正在运行的应用程序输入需要此类的代码时,我没有得到任何编译错误等仅此异常...

Is there some other place I need to add the jar

还有其他地方我需要添加jar

3 个解决方案

#1


After reading this added the jar to the MANIFEST.MF, which solved the problem. As I understand it, eclipse starts several classloaders which only sees what MANIFEST.MF tells them to see and ingnores the build path...

读完之后,将jar添加到MANIFEST.MF,解决了这个问题。据我了解,eclipse启动了几个类加载器,它们只能看到MANIFEST.MF告诉他们看到的内容并且无法构建构建路径......

#2


How are you running your plug-in? You may need to add the JAR to the class path in the VM arguments.

你是如何运行插件的?您可能需要将JAR添加到VM参数中的类路径。

#3


In our experience a NoClassDefFoundError can sometimes mean that more than one version of a Class are found, as there is also a ClassNotFoundException that's normally thrown if a class cannot be found.

根据我们的经验,NoClassDefFoundError有时可能意味着找到了多个Class版本,因为如果找不到类,通常还会引发ClassNotFoundException。

Another reason in your case (XML parser) might be something with endorsed classes. Are you directly importing the jdom classes or something like org.w3c...? If so, have a look at the "endorsed classes" system of Java, something that I just recently came across.

在您的情况下(XML解析器)的另一个原因可能是具有背书类的东西。你直接导入jdom类或类似org.w3c ......?如果是这样,看看Java的“认可课程”系统,这是我刚刚遇到的。

#1


After reading this added the jar to the MANIFEST.MF, which solved the problem. As I understand it, eclipse starts several classloaders which only sees what MANIFEST.MF tells them to see and ingnores the build path...

读完之后,将jar添加到MANIFEST.MF,解决了这个问题。据我了解,eclipse启动了几个类加载器,它们只能看到MANIFEST.MF告诉他们看到的内容并且无法构建构建路径......

#2


How are you running your plug-in? You may need to add the JAR to the class path in the VM arguments.

你是如何运行插件的?您可能需要将JAR添加到VM参数中的类路径。

#3


In our experience a NoClassDefFoundError can sometimes mean that more than one version of a Class are found, as there is also a ClassNotFoundException that's normally thrown if a class cannot be found.

根据我们的经验,NoClassDefFoundError有时可能意味着找到了多个Class版本,因为如果找不到类,通常还会引发ClassNotFoundException。

Another reason in your case (XML parser) might be something with endorsed classes. Are you directly importing the jdom classes or something like org.w3c...? If so, have a look at the "endorsed classes" system of Java, something that I just recently came across.

在您的情况下(XML解析器)的另一个原因可能是具有背书类的东西。你直接导入jdom类或类似org.w3c ......?如果是这样,看看Java的“认可课程”系统,这是我刚刚遇到的。