Page 1 of 1

JBoss 7 config

PostPosted: Tue Oct 15, 2013 11:19 am
by jason
JBoss AS7 has a class loading mechanism which is different from previous versions. See generally:

https://docs.jboss.org/author/display/A ... ing+in+AS7

It includes a module named javax.xml.bind.api; to get docx4j working in your WAR, you just need to include WEB-INF/jboss-deployment-structure.xml containing:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
   
    <deployment>
        <dependencies>
           
            <module name="com.sun.xml.bind" />
           
        </dependencies>
    </deployment>
</jboss-deployment-structure>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Details/discussion

jboss-as-7.1.1.Final\modules\javax\xml\bind\api\main says:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<module xmlns="urn:jboss:module:1.1" name="javax.xml.bind.api">


    <dependencies>
        <module name="javax.activation.api" export="true"/>
        <module name="javax.xml.stream.api"/>
        <module name="com.sun.xml.bind" services="import"/>
        <module name="javax.api"/>
    </dependencies>

    <resources>
        <resource-root path="jboss-jaxb-api_2.2_spec-1.0.3.Final.jar"/>
        <!-- Insert resources here -->
    </resources>
</module>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


jboss-as-7.1.1.Final\modules\com\sun\xml\bind\main says:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<module xmlns="urn:jboss:module:1.1" name="com.sun.xml.bind">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <resources>
        <resource-root path="jaxb-impl-2.2.4.jar"/>
        <resource-root path="jaxb-xjc-2.2.4.jar"/>
        <!-- Insert resources here -->
    </resources>

    <dependencies>
        <module name="javax.api" />
        <module name="javax.xml.bind.api" />
        <module name="javax.xml.stream.api" />
    </dependencies>
</module>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


so you might think the following would also work:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
   
    <deployment>
        <dependencies>
           
            <module name="javax.xml.bind.api" />
           
        </dependencies>
    </deployment>
</jboss-deployment-structure>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


but it didn't seem to, perhaps because <property name="jboss.api" value="private"/> is given effect?

Re: JBoss 7 config

PostPosted: Sat Jan 18, 2014 2:55 am
by asyal
Hi jason,

I am new to docx4j. I have my application running on JBoss As 7.1.1 and jdk1.6. I have gone through various posts but I am still not able to resolve the issue of
java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.jaxb.Context

My application uses maven to find docx4j jars. Here is the maven entry.
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>2.8.1</version>
</dependency>

My java code is comething like
Inputstream istream = ctx.getResourceAsStream("/WEB-INF/g17Templates/"+templateName);
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(istream); --> this is where i start getting the error mentioned.

Here are somethings which I tried.
1) included jboss-deployment-structure.xml in WEB-INF folder.I ahve my web.xml and spring xml files here only in this folder. i used the sample from your post.
2) copied docx4j jar in the standalone/deployment folder, along with the .war file.
3) added docx4j as a module and mentioned <module name="com.sun.xml.bind" /> as a dependency.

None of the above is working for me.

Shoudl i try copying docx4j jars into the jboss lib folder? Will that help?
Is there any other way to tell jboss not to use its own jaxb implementation and use docx4j instead?

Could you please help me ?

Re: JBoss 7 config

PostPosted: Sun Jan 19, 2014 6:02 am
by jason
asyal wrote:java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.jaxb.Context


Include docx4j in you WAR's lib dir

asyal wrote:Is there any other way to tell jboss not to use its own jaxb implementation and use docx4j instead?


docx4j is not, itself, a JAXB implementation; it just relies on there being a JAXB implementation present; in JBOSS, you need WEB-INF/jboss-deployment-structure.xml to put JAXB onto the classpath

Re: JBoss 7 config

PostPosted: Mon Jan 20, 2014 8:15 pm
by asyal
Hi Jason,

What i did today was to put these jar's in the deployment folder along with my project's .war file.
docx4j-2.8.1.jar
jaxb-svg11-1.0.2.jar
jaxb-xmldsig-core-1.0.0.jar
jaxb-xslfo-1.0.1.jar
serializer-2.7.1.jar
xalan-2.7.1.jar

I have not made any specific modules for these jars and simply included them in the standalone\deployment folder. My thought of including these specific jars directly in the deployment folder was that maybe jboss will pick them up instead of going here and there.

The specific docx4j jar is there in the lib folder of my project's .war file.

Still on running the code either I am getting
java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.jaxb.Context error
or i get
java.util.NoSuchElementException
at java.util.Collections$EmptySet$1.next(Collections.java:2912) [rt.jar:1.6.0_31]
at java.util.Collections$1.nextElement(Collections.java:3389) [rt.jar:1.6.0_31]
at org.docx4j.utils.Log4jConfigurator.configure(Log4jConfigurator.java:42) [docx4j-2.8.1.jar:]
at org.docx4j.jaxb.Context.<clinit>(Context.java:51) [docx4j-2.8.1.jar:]

I tried restarting the server multiple times just to ensure incase any jar did not got deployed properly.

I have also created jboss-deployment-structure.xml in my project's WEB-INF folder.

Still facing the same issue.

Re: JBoss 7 config

PostPosted: Tue Jul 01, 2014 11:23 pm
by Shani
Can't you still find any solution to the issue?

Re: JBoss 7 config

PostPosted: Fri Jul 11, 2014 3:24 am
by irrrina
Hello,

I have the same issue and despite having tried many configurations suggested on this forum and a few others, I still cannot get around it.

I have a piece of code using docx4j-3.1.0 that I compiled from Git that replaces bookmarks in a given .docx document. The code works fine locally (called from a Main class in my Eclipse environment) and also if used in a Tomcat server. However, when deployed in the context of an EAR on JBoss 7.1.1, I get the error below:

Code: Select all
- A Docx4JException occurred
org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't get [Content_Types].xml from ZipFile
   at org.docx4j.openpackaging.io3.Load3.get(Load3.java:134)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:459)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:376)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:342)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:307)
   at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:174)


The deployment on JBoss has the following structure:
Code: Select all
   myapp.ear
      APP-INF
      META-INF
      lib
      myapp.war
         WEB-INF


The folder myapp.ear\META-INF also contains a jboss-deployment-structure.xml (JDS) file. File's content is below:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <ear-subdeployments-isolated>true</ear-subdeployments-isolated>
    <deployment>
        <exclusions>
            <module name="org.apache.log4j"/>
            <module name="org.apache.commons.logging"/>
            <module name="javax.jms.api"/>
            <module name="javax.xml.bind.api"/>
        </exclusions>
        <dependencies>
            <module name="org.apache.xerces" />
        </dependencies>
    </deployment>
    <sub-deployment name="myapp.war">
        <exclusions>
            <module name="org.apache.log4j"/>
            <module name="org.apache.commons.logging"/>
            <module name="javax.jms.api"/>
            <module name="javax.xml.bind.api"/>
        </exclusions>
    </sub-deployment>
</jboss-deployment-structure>

I've tried:
  • adding the docx4j library and all its dependencies in the myapp.war/WEB-INF/lib and myapp.ear/lib folders
  • adding the <module name="com.sun.xml.bind" /> dependency to the JDS file
  • explicitly excluding the <module name="com.sun.xml.bind" /> dependency from JDS file
  • creating a JDS file in myapp.war/WEB-INF
  • creating a module at jboss root level for docx4j and a few of its dependencies that were referenced on several forum posts (jaxb-api, jaxb-impl, jaxb-svg, jaxb-xslfo, jaxb-xmldsig-core, serializer and xalan)
  • started JBoss in debug mode

When I removed the com.sun.xml.bind dependency, I got a different error:

Code: Select all
[javax.xml.bind.JAXBException: ClassCastException: attempting to cast jar:file:/C:/jboss7.1.1/modules/javax/xml/bind/api/main/jboss-jaxb-api_2.2_spec-1.0.3.Final.jar!/javax/xml/bind/JAXBContext.class to jar:file:/C:/java64/1.7.0_17/jre/lib/rt.jar!/javax/xml/bind/JAXBContext.class.  Please make sure that you are specifying the proper ClassLoader.]]


I also created a simple JSP page to show where a class is loaded from and no matter what I did, the JAXBContext.class got loaded exclusively from the jboss modules (never from the local jars). However, I even tried replacing that jar with the jar from docx4j dependencies (which is version 2.1) and the execution is no better.

I have 2 more things I'd like to test - or any other suggestions you may have on this forum:
1. setting up a jaxb.properties - is it maybe possible to set up there where this JAXBContext class should be loaded from ?
2. get nosey and change the code from docx4j (although I do not know at this point how), the problem seems to be at this level:

Code: Select all
extract from org.docx4j.jaxb.Context

java.lang.ClassLoader classLoader = Context.class.getClassLoader();

jc = JAXBContext.newInstance("org.docx4j.wml:org.docx4j.w14:org.docx4j.w15:" +
"org.docx4j.schemas.microsoft.com.office.word_2006.wordml:" +   
"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.docx4j.docProps.coverPageProps:" + "org.opendope.xpaths:org.opendope.conditions:org.opendope.questions:org.opendope.answers:org.opendope.components:org.opendope.SmartArt.dataHierarchy:" + "org.docx4j.math:" + "org.docx4j.sharedtypes:org.docx4j.bibliography",classLoader );


Any suggestion you may have at this point is highly appreciated !

Thanks,
Irina

Re: JBoss 7 config

PostPosted: Fri Jul 11, 2014 8:04 am
by jason
You need to start with a simple project, using the jboss-deployment-structure.xml in the first post of this thread.

Once you have that working, you can add complexity.

<exclusions>
<module name="javax.xml.bind.api"/>


Why?

no matter what I did, the JAXBContext.class got loaded exclusively from the jboss modules (never from the local jars). However, I even tried replacing that jar with the jar from docx4j dependencies (which is version 2.1)


docx4j's pom doesn't explicitly declare a dependency on JAXB, so this seems confused...

Locking this topic now. If you (or anyone else) continue to have issues, please start your own thread.