2

我想知道是否有人对设置有同样的问题:

  1. 网络逻辑 12c
  2. Docx4J 2.8.1
  3. 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 实现,但到目前为止我已经尝试过:

  1. 不将任何 jaxb jar 放入库中
  2. 放置版本的 jaxb jar:2.1.7、2.2.4、2.2.6,都不起作用。

此外,如果它有任何帮助,如果我从 void main 运行它,同样的方法也有效,如果它是从 WebLogic 服务器执行的,它就不起作用,所以我确信存在类加载问题。

4

1 回答 1

0

据报道,要让 docx4j 与 Weblogic 12c 一起使用,您可以升级 eclipselink,或切换到 JAXB 参考实现。

要升级 Eclipselink,请参阅http://www.docx4java.org/forums/weblogic-f25/how-to-update-to-eclipselink-2-5-in-web-t1574.html

http://www.docx4java.org/forums/weblogic-f25/classcastexception-in-weblogic-12c-t1643.html#p5675建议切换到 JAXB RI 是一种更好的方法,目前无论如何。

请注意,要将 Eclipselink JAXB 实现与 docx4j 一起使用,您应该使用 docx4j 3 beta 或更高版本。

于 2013-11-15T09:24:48.930 回答