I want to implement a java desktop-application using eclipse that takes the information from the user and saves it into excel spreadsheet (using docx4j), but I faced a problem at the very beginning.
I'm trying to load the spreadsheet using this code:
private static void load(String filepath) {
SpreadsheetMLPackage exc;
try {
exc = SpreadsheetMLPackage.load(new java.io.File(filepath));
} catch (Docx4JException e) {
e.printStackTrace();
}
}
but I'm getting this error:
[main] ERROR org.docx4j.jaxb.Context - Cannot initialize context
javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "org.plutext.jaxb.xmldsig" doesnt contain ObjectFactory.class or jaxb.index
- with linked exception:
[javax.xml.bind.JAXBException: "org.plutext.jaxb.xmldsig" doesnt contain ObjectFactory.class or jaxb.index]
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at org.docx4j.jaxb.Context.<clinit>(Context.java:158)
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:679)
at org.docx4j.openpackaging.io3.Load3.get(Load3.java:132)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:454)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:371)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:262)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:242)
at org.docx4j.openpackaging.packages.SpreadsheetMLPackage.load(SpreadsheetMLPackage.java:97)
Note: 1- Creating new spreadsheet works fine. 2- The external jars added to my project are: docx4j-3.2.1, jcl-over-slf4j-1.7.12, slf4j-api-1.7.12, slf4j-simple-1.7.12. 3- I searched for a solution on google and I found that I must add org.apache.xalan and org.apache.xml.serializer jars to my project but still it didn't work.
You need to include all docx4j's dependencies.
The cause of this specific error is missing http://www.docx4java.org/docx4j/docx4j-3_2_0/dependencies/jaxb-xmldsig-core-1.0.0.jar