2 Replies Latest reply on Oct 14, 2013 2:48 AM by Julian Ivancsuk

    Cannot use docx4j inside of JBoss 7

    Jacob Davis Newbie

      I was able to successfully create a simple project with docx4j ( http://www.docx4java.org ).  This simple project successfully created and wrote on a .docx document.  Now I am trying to accomplish the same thing inside of a bigger project.  This bigger project is a webapp running in JBoss AS 7.1. However, at my first docx4j related line of code:

       

      {code}WordprocessingMLPackage wmlp = WordprocessingMLPackage.createPackage();{code}

       

       

      It runs into an error:

       

      {code}java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.jaxb.Context

                at org.docx4j.openpackaging.parts.JaxbXmlPart.<init>(JaxbXmlPart.java:79) [docx4j-2.8.1.jar:]

                at org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware.<init>(JaxbXmlPartXPathAware.java:64) [docx4j-2.8.1.jar:]

                at org.docx4j.openpackaging.parts.WordprocessingML.DocumentPart.<init>(DocumentPart.java:157) [docx4j-2.8.1.jar:]

                at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.<init>(MainDocumentPart.java:76) [docx4j-2.8.1.jar:]

                at org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage(WordprocessingMLPackage.java:432) [docx4j-2.8.1.jar:]

                at org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage(WordprocessingMLPackage.java:421) [docx4j-2.8.1.jar:]

                at foo.servlets.bar.DocxServlet.doGet(DocxServlet.java:101) [classes:]

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                at foo.includes.other.ServletNameSetFilter.doFilter(ServletNameSetFilter.java:83) [fooClasses.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                at foo.includes.other.HtmlEscapeFilter.doFilter(HtmlEscapeFilter.java:67) [fooClasses.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                at foo.includes.other.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:64) [fooClasses.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

                at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

                at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:505) [jbossweb-7.0.13.Final.jar:]

                at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:445) [jbossweb-7.0.13.Final.jar:]

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

                at java.lang.Thread.run(Thread.java:636) [rt.jar:1.6.0_20]{code}

       

      Also, when I stop and restart my server without rebuilding my EAR, this error doesn't show up and instead I get a NoSuchElementException from the same method call (createPackage()):

       

      I believe it has to do with the fact that JBoss has its own JAXB implementation, but JAXBContext is initialized within the docx4j library. Here is the code (from http://www.docx4java.org/trac/docx4j/browser/trunk/docx4j/src/main/java/org/docx4j/jaxb/Context.java):

       

      {code}jc = JAXBContext.newInstance("org.docx4j.wml:" +

                      "org.docx4j.dml:org.docx4j.dml.chart:org.docx4j.dml.chartDrawing:org.docx4j.dml.compatibility:org.docx4j.dml.diagram:org.docx4j.dml.lockedCanvas:org.docx4j.dml.picture:org.docx4j.dml.wordprocessingDrawing:org.docx4j.dml.spreadsheetdrawing:org.docx4j.dml.diagram2008:" +

                      // All VML stuff is here, since compiling it requires WML and DML (and MathML), but not PML or SML

                      "org.docx4j.vml:org.docx4j.vml.officedrawing:org.docx4j.vml.wordprocessingDrawing:org.docx4j.vml.presentationDrawing:org.docx4j.vml.spreadsheetDrawing:org.docx4j.vml.root:" +

                      "org.opendope.xpaths:org.opendope.conditions:org.opendope.questions:org.opendope.components:org.opendope.SmartArt.dataHierarchy:" +

                      "org.docx4j.math:" +

                      "org.docx4j.sharedtypes:org.docx4j.bibliography",classLoader );

      log.info("loaded " + jc.getClass().getName() + " .. loading others ..");

       

       

      jcThemePart = jc; //JAXBContext.newInstance("org.docx4j.dml",classLoader );

      jcDocPropsCore = JAXBContext.newInstance("org.docx4j.docProps.core:org.docx4j.docProps.core.dc.elements:org.docx4j.docProps.core.dc.terms",classLoader );

      jcDocPropsCustom = JAXBContext.newInstance("org.docx4j.docProps.custom",classLoader );

      jcDocPropsExtended = JAXBContext.newInstance("org.docx4j.docProps.extended",classLoader );

      jcXmlPackage = JAXBContext.newInstance("org.docx4j.xmlPackage",classLoader );

      jcRelationships = JAXBContext.newInstance("org.docx4j.relationships",classLoader );

      jcCustomXmlProperties = JAXBContext.newInstance("org.docx4j.customXmlProperties",classLoader );

      jcContentTypes = JAXBContext.newInstance("org.docx4j.openpackaging.contenttype",classLoader );

       

       

      jcSectionModel = JAXBContext.newInstance("org.docx4j.model.structure.jaxb",classLoader );

       

       

      jcXmlDSig = JAXBContext.newInstance("org.plutext.jaxb.xmldsig",classLoader );{code}

       

      From what I have observed, it seems that I might need to put a jaxb.properties file specifying which jaxb implementation to use in every package listed in each JAXBContext instance above.  Is this correct?  Is there anything I am missing?