1

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.

prime
  • 769
  • 1
  • 13
  • 27
  • Did you really "search the internet"? There are various questions in this very forum concerning JBoss and docx4j. See if this thread helps: http://stackoverflow.com/questions/16204635/cannot-use-docx4j-inside-of-jboss-7 There is also a forum for this, complete with JBoss 7 configuration instructions: http://www.docx4java.org/forums/jboss-f29/jboss-7-config-t1678.html – Ben Jul 01 '14 at 12:05
  • I followed stackoverflow.com/questions/16204635/ link. But in there only one solution. It is have to use jboss EAP 6.2 version. I want to work with jboss 7 version. docx4java.org/forums/jboss-f29/jboss-7-config-t1678.html ... In that link also, there isn't a solution. There is only about the issue. – prime Jul 01 '14 at 12:21
  • Using the EAP 6.2 version is just _one_ of the answers. I understand you are using JBoss 7.x -- that's the same version in that thread. Either way, it comes down to how the new classloading works in JBoss, and there's plenty of stuff about this in the docx4j thread I link to. – Ben Jul 01 '14 at 12:22
  • (You say there's no solution in that link. There is). – Ben Jul 01 '14 at 12:28

1 Answers1

6

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>
Mathieu Fortin
  • 1,048
  • 7
  • 17