Getting java.lang.NoClassDefFoundError: org/apache/xerces/dom/ElementNSImpl with Apache ODF Toolkit

Ravi Joshi picture Ravi Joshi · Aug 9, 2013 · Viewed 15.7k times · Source

I am trying to read an ods file using Apache ODF Toolkit. I am getting java.lang.NoClassDefFoundError error while while trying to load the Spreadsheet using below code-

SpreadsheetDocument data = SpreadsheetDocument.loadDocument(file);

Below is the error trace-

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/dom/ElementNSImpl
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at test.read.ODSFile.ReadODS.main(ReadODS.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.dom.ElementNSImpl
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 25 more

Below is the project structure, which shows the classpath- Eclipse screenshot

Is there any dependencies missing?

Answer

Nomada picture Nomada · Sep 8, 2013

It seems your code can not find the class: Caused by: java.lang.ClassNotFoundException: org.apache.xerces.dom.ElementNSImpl

from ODF Toolkit

Note: ODFDOM requires Apache Xerces. The jar file xercesImpl.jar also must exist in a folder lib next to odfxsltrunner.jar file, or it must be in the classpath. The ODF XSLT Runner NetBeans projects includes a reference to xersesImpl.jar in the runtime classpath which has to be adapted after checking out the project.