使用Apache ODF Toolkit获取java.lang.NoClassDefFoundError:org / apache / xerces / dom / ElementNSImpl

时间:2013-08-09 13:35:36

标签: java odf odfdom

我正在尝试使用ods阅读Apache ODF Toolkit文件。我在尝试使用以下代码加载电子表格时遇到java.lang.NoClassDefFoundError错误 -

SpreadsheetDocument data = SpreadsheetDocument.loadDocument(file);

以下是错误跟踪 -

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

以下是项目结构,显示了类路径 - Eclipse screenshot

是否缺少任何依赖项?

1 个答案:

答案 0 :(得分:1)

看来您的代码无法找到该类: 引起:java.lang.ClassNotFoundException:org.apache.xerces.dom.ElementNSImpl

来自ODF Toolkit

注意:ODFDOM需要Apache Xerces。 jar文件xercesImpl.jar也必须存在于odfxsltrunner.jar文件旁边的文件夹lib中,或者它必须位于类路径中。 ODF XSLT Runner NetBeans项目在运行时类路径中包含对xersesImpl.jar的引用,在检出项目后必须对其进行调整。