Search code examples
javadependenciesodf

What dependencies to use for APACHE ODF TOOLKIT (INCUBATING)


I am trying to load a .ods file with the code:

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

I've added the import statement to show which package I am using.

However I keep getting java.lang.NoClassDefFoundError. I've tried adding many different libraries. At the moment I have these libraries in my eclipse build path: libraries in my eclipse build path

And am getting this error

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

Any suggestion on how to get my code running or any alternative my to do simple read and writes to .ods files would be greatly appeciated.


Solution

  • You have to add commons-validator-1.5.0.jar, jena-core-2.11.2.jar, jena-iri-1.0.2.jar at least.

    The full dependencies jars could be got via maven command 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
    

    If you don't want to get java.lang.NoClassDefFoundError in future, you should also add these jars. They can be found in odfvalidator-1.1.8-incubating.war of odftoolkit-0.6.2-incubating-bin.zip.