2017-05-25 131 views
1

我試圖加載的.ods與代碼文件:哪些依賴於使用APACHE ODF工具包(孵化)

import org.odftoolkit.simple.SpreadsheetDocument; 
SpreadsheetDocument data = SpreadsheetDocument.loadDocument(f); 

我已經添加了import語句,以顯示我使用的包。

但是我不斷收到java.lang.NoClassDefFoundError。我試過添加許多不同的庫。目前,我有這些庫在我的Eclipse構建路徑:libraries in my eclipse build path

和我得到這個錯誤

Exception in thread "main" java.lang.NoClassDefFoundError: com/hp/hpl/jena/rdf/model/RDFNode 
    at org.odftoolkit.odfdom.pkg.OdfFileDom.initialize(OdfFileDom.java:215) 
    at org.odftoolkit.odfdom.pkg.manifest.OdfManifestDom.initialize(OdfManifestDom.java:74) 
    at org.odftoolkit.odfdom.pkg.OdfFileDom.<init>(OdfFileDom.java:132) 
    at org.odftoolkit.odfdom.pkg.manifest.OdfManifestDom.<init>(OdfManifestDom.java:63) 
    at org.odftoolkit.odfdom.pkg.OdfFileDom.newFileDom(OdfFileDom.java:189) 
    at org.odftoolkit.odfdom.pkg.OdfPackage.parseManifest(OdfPackage.java:1187) 
    at org.odftoolkit.odfdom.pkg.OdfPackage.readZip(OdfPackage.java:454) 
    at org.odftoolkit.odfdom.pkg.OdfPackage.initializeZip(OdfPackage.java:425) 
    at org.odftoolkit.odfdom.pkg.OdfPackage.<init>(OdfPackage.java:256) 
    at org.odftoolkit.odfdom.pkg.OdfPackage.loadPackage(OdfPackage.java:318) 
    at org.odftoolkit.simple.Document.loadDocument(Document.java:319) 
    at org.odftoolkit.simple.SpreadsheetDocument.loadDocument(SpreadsheetDocument.java:203) 
    at FirstLoadComponent.main(FirstLoadComponent.java:11) 
Caused by: java.lang.ClassNotFoundException: com.hp.hpl.jena.rdf.model.RDFNode 
    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) 
    ... 13 more 

如何把我的代碼運行的任何建議或任何其他我做簡單的讀取和寫入.ods文件將會被大大改變。

回答

1

您必須至少添加commons-validator-1.5.0.jar,jena-core-2.11.2.jar,jena-iri-1.0.2.jar

完整的依賴關係罐可以通過maven命令mvn dependency:tree獲得。

 
org.apache.odftoolkit:odfdom-java:jar:0.8.11-incubating 
+- org.apache.odftoolkit:taglets:jar:0.8.11-incubating:compile 
| \- com.sun:tools:jar:1.7.0:system 
+- xerces:xercesImpl:jar:2.9.1:compile 
+- xml-apis:xml-apis:jar:1.3.04:compile 
+- org.apache.jena:jena-core:jar:2.11.2:compile 
| +- org.slf4j:slf4j-api:jar:1.7.6:compile 
| +- org.apache.jena:jena-iri:jar:1.0.2:compile 
| +- org.slf4j:slf4j-log4j12:jar:1.7.6:compile 
| \- log4j:log4j:jar:1.2.17:compile 
+- net.rootdev:java-rdfa:jar:0.4.2:compile 
\- commons-validator:commons-validator:jar:1.5.0:compile 
    +- commons-beanutils:commons-beanutils:jar:1.9.2:compile 
    +- commons-digester:commons-digester:jar:1.8.1:compile 
    +- commons-logging:commons-logging:jar:1.2:compile 
    \- commons-collections:commons-collections:jar:3.2.2:compile 

如果你不想讓未來java.lang.NoClassDefFoundError, 你還應該添加這些罐子。他們可以在odfvalidator-1.1.8-incubating.warodftoolkit-0.6.2-incubating-bin.zip