问题
I am using docx4j to parse docx file. I downloaded all JARs from docx4j site docx4j downloads.
When I used it in code, it gives runtime error at very first line of code: -
WordprocessingMLPackage template = WordprocessingMLPackage.load(new FileInputStream(new File("Global_OPO_Profile_EN.docx")));
Exception is:
INFO org.docx4j.utils.Log4jConfigurator .configure line 45 - Since your log4j configuration (if any) was not found, docx4j has configured log4j automatically.
ERROR org.docx4j.jaxb.Context .<clinit> line 64 - PANIC! No suitable JAXB implementation available
javax.xml.bind.JAXBException: Unable to locate jaxb.properties for package org.docx4j.relationships
at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:205)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:149)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:281)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:47)
at org.docx4j.jaxb.Context.<clinit>(Context.java:56)
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:658)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:301)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:245)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
at com.atos.docx4jtest.Docx4iTest.main(Docx4iTest.java:15)
INFO org.docx4j.jaxb.Context .<clinit> line 76 - loading Context jc
ERROR org.docx4j.jaxb.Context .<clinit> line 102 - Cannot initialize context
javax.xml.bind.JAXBException: Unable to locate jaxb.properties for package org.docx4j.wml
at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:205)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:149)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:281)
at org.docx4j.jaxb.Context.<clinit>(Context.java:77)
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:658)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:301)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:245)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
at com.atos.docx4jtest.Docx4iTest.main(Docx4iTest.java:15)
ERROR org.docx4j.openpackaging.contenttype.ContentTypeManager .parseContentTypesFile line 690 - java.lang.NullPointerException
org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:691)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:301)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:245)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
at com.atos.docx4jtest.Docx4iTest.main(Docx4iTest.java:15)
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:658)
... 8 more
回答1:
Java 1.5 does not include JAXB, so you need to download the JAXB reference implementation, and add it to your class path.
来源:https://stackoverflow.com/questions/12363169/docx4j-no-suitable-jaxb-implementation-available-runtime-error-java-1-5