prime
prime

Reputation: 809

Use docx4j library with jboss 7

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.

Upvotes: 1

Views: 2169

Answers (1)

Mathieu Fortin
Mathieu Fortin

Reputation: 1058

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>

Upvotes: 6

Related Questions