views:

316

answers:

3

I'm developing a eclipse plugin rcp and I'm running into a 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...

Is there some other place I need to add the jar

A: 

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

Matt Kane
I'm running it as an Eclipse Application...
jau
A: 

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.

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.

Ridcully
NoClassDefFoundError will be thrown if compiled code refers to a class that is not on the classpath. ClassNotFoundException will be thrown if when trying to use reflection to instantiate a class, the class as named cannot be found.
akf
+1  A: 

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...

jau