加载文档

时间:2018-01-05 07:17:01

标签: jaxb osgi apache-karaf osgi-bundle docx4j

我尝试在我的应用程序中使用docx4j 3.3.6和Java 1.8,它运行在apache karaf上。目前,我在尝试加载文档时:

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File("C:\\some_document.docx"));

我得到以下例外情况:

  

javax.xml.bind.PropertyException:property   " com.sun.xml.bind.namespacePrefixMapper"必须是类型的实例   com.sun.xml.bind.marshaller.NamespacePrefixMapper,不是   org.docx4j.jaxb.NamespacePrefixMapper at   com.sun.xml.bind.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:511)     在   org.docx4j.jaxb.NamespacePrefixMapperUtils.tryUsingRI(NamespacePrefixMapperUtils.java:105)     在   org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:84)     在org.docx4j.jaxb.Context。(Context.java:117)at   org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:733)     在org.docx4j.openpackaging.io3.Load3.get(Load3.java:134)at   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:462)     在   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:379)     在   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:270)     在   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:250)     在   org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:168)

然后是下面的例外情况:

  

javax.xml.bind.JAXBException:JAXB:既不是参考实现   还是Java 6的实现?在   org.docx4j.jaxb.NamespacePrefixMapperUtils.tryUsingRI(NamespacePrefixMapperUtils.java:117)     在   org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:84)     在org.docx4j.jaxb.Context。(Context.java:117)at   org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:733)     在org.docx4j.openpackaging.io3.Load3.get(Load3.java:134)at   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:462)     在   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:379)     在   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:270)     在   org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:250)     在   org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:168)

Bellow是我在我的karaf上安装的功能中使用的捆绑包的副本。

<feature name="docx4j" version="1.0">
    <bundle>wrap:mvn:org.docx4j/docx4j/3.3.4</bundle>
    <bundle>wrap:mvn:commons-io/commons-io/2.4</bundle>
    <bundle>wrap:mvn:org.apache.xmlgraphics/xmlgraphics-commons/2.1</bundle>
    <bundle>wrap:mvn:com.googlecode.jaxb-namespaceprefixmapper-interfaces/JAXBNamespacePrefixMapper/2.2.4</bundle>
    <bundle>wrap:mvn:org.plutext/jaxb-svg11/1.0.2</bundle>
    <bundle>wrap:mvn:com.sun.xml.bind/jaxb-impl/2.2.4-1</bundle>
    <bundle>wrap:mvn:org.docx4j/docx4j-MOXy-JAXBContext/3.3.6</bundle>
    <bundle>wrap:mvn:xalan/xalan/2.7.2</bundle>
    <bundle>wrap:mvn:xalan/serializer/2.7.2</bundle>
    <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-core/2.7.3</bundle>
    <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-databind/2.7.3</bundle> 
    <bundle>wrap:mvn:org.apache.xmlgraphics/xmlgraphics-commons/2.1</bundle> 
    <bundle>wrap:mvn:com.thedeanda/lorem/2.0</bundle>
    <bundle>wrap:mvn:com.google.guava/guava/19.0</bundle>
    <bundle>wrap:mvn:commons-codec/commons-codec/1.10</bundle> 
    <bundle>wrap:mvn:net.arnx/wmf2svg/0.9.8</bundle>
    <bundle>wrap:mvn:net.engio/mbassador/1.2.4.2</bundle>
    <bundle>wrap:mvn:org.antlr/antlr-runtime/3.5.2</bundle>
    <bundle>wrap:mvn:org.antlr/stringtemplate/3.2.1</bundle>
    <bundle>wrap:mvn:org.apache.avalon.framework/avalon-framework-api/4.3.1</bundle>
    <bundle>wrap:mvn:org.apache.avalon.framework/avalon-framework-impl/4.3.1</bundle>
    <bundle>wrap:mvn:org.apache.commons/commons-lang3/3.4</bundle>
    <bundle>wrap:mvn:org.apache.httpcomponents/httpclient/4.5.2</bundle>
    <bundle>wrap:mvn:xerces/xercesImpl/2.11.0</bundle>
    <bundle>wrap:mvn:org.apache.httpcomponents/httpcore/4.4.8</bundle>
    <bundle>wrap:mvn:org.codehaus.mojo/jaxb2-maven-plugin/2.2</bundle>
    <bundle>wrap:mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant-1.7.0/1.0-m2</bundle>

</feature>

与JAXB会发生某种冲突吗?我试图在docx4j 3.3.6要求的功能中使用相同的依赖项,但这似乎没有做到这一点。有什么建议?

更新

我已经通过删除多个依赖项来更改我的功能xml

<feature name="docx4j" version="1.0">
    <bundle>wrap:mvn:org.docx4j/docx4j/3.3.4</bundle>
    <bundle>wrap:mvn:commons-io/commons-io/2.4</bundle>
    <bundle>wrap:mvn:org.apache.xmlgraphics/xmlgraphics-commons/2.1</bundle>
    <bundle>wrap:mvn:org.plutext/jaxb-svg11/1.0.2</bundle>
    <bundle>wrap:mvn:xalan/xalan/2.7.2</bundle>
    <bundle>wrap:mvn:xalan/serializer/2.7.2</bundle>
    <bundle>mvn:com.fasterxml.jackson.core/jackson-core/2.7.3</bundle>
    <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/2.7.3</bundle> 
    <bundle>wrap:mvn:com.thedeanda/lorem/2.0</bundle>
    <bundle>mvn:com.google.guava/guava/19.0</bundle>
    <bundle>wrap:mvn:commons-codec/commons-codec/1.10</bundle> 
    <bundle>wrap:mvn:net.arnx/wmf2svg/0.9.8</bundle>
    <bundle>mvn:net.engio/mbassador/1.2.4.2</bundle>
    <bundle>wrap:mvn:org.antlr/antlr-runtime/3.5.2</bundle>
    <bundle>wrap:mvn:org.antlr/stringtemplate/3.2.1</bundle>
    <bundle>wrap:mvn:org.apache.avalon.framework/avalon-framework-api/4.3.1</bundle>
    <bundle>wrap:mvn:org.apache.avalon.framework/avalon-framework-impl/4.3.1</bundle>
    <bundle>wrap:mvn:org.apache.commons/commons-lang3/3.4</bundle>
    <bundle>wrap:mvn:org.apache.httpcomponents/httpclient/4.5.2</bundle>
    <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant-1.7.0/1.0-m2</bundle>
</feature>

现在我得到一个新的例外

  

java.lang.NoClassDefFoundError:   org / apache / xml / serializer / SerializerTrace at   java.lang.ClassLoader.defineClass1(Native Method)[:1.8.0_91] at   java.lang.ClassLoader.defineClass(ClassLoader.java:763)[:1.8.0_91] at   org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.defineClass(BundleWiringImpl.java:2310)     在   org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.findClass(BundleWiringImpl.java:2094)     在   org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1518)     在   org.apache.felix.framework.BundleWiringImpl.access $ 200(BundleWiringImpl.java:79)     在   org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.loadClass(BundleWiringImpl.java:1958)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_91]     在   org.apache.xalan.processor.ProcessorStylesheetElement.getStylesheetRoot(ProcessorStylesheetElement.java:123)

我再次发现此异常很奇怪,因为我已将序列化程序包含在我的依赖项中。

0 个答案:

没有答案