我想知道是否有人对设置有同样的问题:
- 网络逻辑 12c
- Docx4J 2.8.1
- Java EE 6
我尝试使用 Docx4J 获取某个 Microsoft Word 2007 文档的内容,但出现如下错误:
当我尝试这样做时:
WordprocessingMLPackage package = WordprocessingMLPackage.load(new File((path));
它会抛出异常,如:
2013-06-05 15:29:12.0283 ERROR Thread-18 org.docx4j.jaxb.NamespacePrefixMapperUtils – name: com.sun.xml.internal.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapperSunInternal@2b0bf3 .. trying RI.
javax.xml.bind.PropertyException: name: com.sun.xml.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapper@2a3c7c
at org.eclipse.persistence.jaxb.JAXBMarshaller.setProperty(JAXBMarshaller.java:590)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.tryUsingRI(NamespacePrefixMapperUtils.java:73)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:64)
at org.docx4j.jaxb.Context.<clinit>(Context.java:56)
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
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)
2013-06-05 15:29:12.0455 ERROR Thread-18 org.docx4j.jaxb.NamespacePrefixMapperUtils – JAXB: neither Reference Implementation nor Java 6 implementation present?
javax.xml.bind.PropertyException: name: com.sun.xml.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapper@2a3c7c
at org.eclipse.persistence.jaxb.JAXBMarshaller.setProperty(JAXBMarshaller.java:590)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.tryUsingRI(NamespacePrefixMapperUtils.java:73)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:64)
at org.docx4j.jaxb.Context.<clinit>(Context.java:56)
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
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)
如上所述,我使用的是 JDK 6,所以这应该是不可能的消息。但是上面的消息被 Docx4J 内部抑制,而是抛出以下异常:
2013-06-05 15:46:38.0392 ERROR Thread-18 com.jonathan.business.catalog.impl.ProductCatalogServiceImpl – Bad [Content_Types].xml
org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:699)
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)
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
... 12 more
2013-06-05 15:46:38.0392 ERROR Thread-18 com.jonathan.business.catalog.impl.ProductCatalogServiceImpl – Bad [Content_Types].xml
org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:699)
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)
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
... 12 more
我按照 Docx4J 论坛中的建议尝试了这个,但没有用。
这个问题也没有答案。
Java 6 应该在内部拥有自己的 JAXB 实现,但到目前为止我已经尝试过:
- 不将任何 jaxb jar 放入库中
- 放置版本的 jaxb jar:2.1.7、2.2.4、2.2.6,都不起作用。
此外,如果它有任何帮助,如果我从 void main 运行它,同样的方法也有效,如果它是从 WebLogic 服务器执行的,它就不起作用,所以我确信存在类加载问题。