Reputation: 359
I am writing an XML file with StAX parser using XmlStreamEventWriter, the stax-utils.jar is added correctly to the classpath in Eclipse. I wanted to use IndentingXMLStreamWriter
class from this jar file but somehow its throwing below exception:
java.lang.NoClassDefFoundError: javanet/staxutils/IndentingXMLStreamWriter
Caused by: java.lang.ClassNotFoundException: javanet.staxutils.IndentingXMLStreamWriter
cannot be found by RCP_PLUGIN_6.20.0.qualifier
The piece of code causing exception is :
XMLEventFactory eventFactory=XMLEventFactory.newInstance();
if(!tmpSettingsXml.exists())
tmpSettingsXml.createNewFile();
XMLStreamWriter xmlStreamWriter=new IndentingXMLStreamWriter(XMLOutputFactory.newInstance().
createXMLStreamWriter(new FileOutputStream(tmpSettingsXml)));
xmlStreamWriter.writeStartDocument();
If the method containing 'IndentingXMLStreamWriter' is being called from other class of the tool its throwing exception, however, if this method is called from main() in other class its perfectly working fine and able to find classes inside jar.
Anyone can suggest what's wrong here?
Upvotes: 1
Views: 1036
Reputation: 20003
An Eclipse/RCP plug-in runs within an OSGi Runtime, which (almost) completely controls its runtime classpath based on the Plug-in Manifest: the MANIFEST.MF file. You need to add any dependencies that aren't your own sources there, and not directly using the Java Build Path UI. The Java Build Path UI isn't locked out because a Plug-in Project is still a Java Project, just with more stuff.
So remove the jar(s) you added to the Java Build Path, open the MANIFEST.MF file in the Plug-in Manifest Editor, and add the jars to the Classpath section on the Runtime tab.
Upvotes: 2