Use docx4j library with jboss 7

♀尐吖头ヾ 提交于 2019-12-11 04:52:46

问题


I try to generate a pptx using pptx4j library. I could generate a pptx successfully. Then I applied the code to a huge project that run on the jboss 7 server. Project is sucessfully deployed on the server. But when I'm trying to run the application it gives following exception.

java.lang.NoClassDefFoundError: com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper

That exception is occurred for following line in the code.

PresentationMLPackage presentationMLPackage = PresentationMLPackage
                .createPackage(); 

Is there a special way run docx4j library on the jboss 7 server. I searched more on Internet but I couldn't find a solution.


回答1:


JBoss AS 7 introduced the concept of modules (bundles) which drastically changed how classes get loaded. You should get yourself familiar with this concept:

https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7

jboss-deployment-structure.xml is a JBoss specific deployment descriptor that can be used to control class loading in a fine grained manner. It should be placed in the top level deployment, in META-INF (or WEB-INF for web deployments). It can do the following:

  • Prevent automatic dependencies from being added
  • Add additional dependencies
  • Define additional modules
  • Change an EAR deployments isolated class loading behaviour
  • Add additional resource roots to a module

When you get a NoClassDefFoundError in JBoss AS 7 you can bet that you have a missing dependency somewhere. As for your specific case, you need to add a dependency on module com.sun.xml.bind.

docx4j even has a page for this:

http://www.docx4java.org/forums/jboss-f29/jboss-7-config-t1678.html

to get docx4j working in your WAR, you just need to include WEB-INF/jboss-deployment-structure.xml containing:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <module name="com.sun.xml.bind" />
       </dependencies>
    </deployment>
</jboss-deployment-structure>


来源:https://stackoverflow.com/questions/24509810/use-docx4j-library-with-jboss-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!