8 Replies Latest reply on Apr 17, 2013 11:41 AM by ouadi_dev

    JBoss 7 Class Loading

    sbourguiba

      Hi,

       

      I have ClassCastException when i try to deploy my EAR in JBoss7.1, i added jboss-structure.xml in ear/META-INF and it's the same problem.

      The problem is that i don't want to remove dom4j.jar from the EAR .

       

      jboss-structure.xml:

      <jboss-deployment-structure>

      <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

                <deployment>

                          <exclusions>

                                    <module name="org.dom4j" />

                          </exclusions>

                </deployment>

                <sub-deployment name="myApp.war">

                          <exclusions>

                                    <module name="org.dom4j" />

                          </exclusions>

                </sub-deployment>

                <sub-deployment name="myEjb.jar">

                          <exclusions>

                                    <module name="org.dom4j" />

                          </exclusions>

                </sub-deployment>

      </jboss-deployment-structure>

       

      Exception:

       

      11:11:15,868 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-3) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}

      11:11:15,868 INFO  [org.hibernate.Version] (MSC service thread 1-3) HHH000412: Hibernate Core {4.0.1.Final}

      11:11:15,868 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-3) HHH000206: hibernate.properties not found

      11:11:15,884 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-3) HHH000021: Bytecode provider name : javassist

      11:11:15,899 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-4) HHH000204: Processing PersistenceUnitInfo [

              name: NonXA_DataSource

              ...]

      11:11:15,977 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.persistenceunit."myApp.ear/myEjb.jar#NonXA_DataSource": org.jboss.msc.service.StartException in service jboss.persistenceunit."myApp.ear/myEjb.jar#NonXA_DataSource": Failed to start service

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_26]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_26]

              at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_26]

      Caused by: org.hibernate.InvalidMappingException: Unable to read XML

              at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:106)

              at org.hibernate.ejb.Ejb3Configuration.addXMLEntities(Ejb3Configuration.java:734)

              at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:603)

              at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)

              at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)

              at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              ... 3 more

      Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

              at org.dom4j.io.SAXReader.read(SAXReader.java:484)

              at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:76)

              ... 10 more

       

      What do you think?

       

      Regadrs

        • 1. Re: JBoss 7 Class Loading
          guinotphil

          Hi,

           

          I can't be sure of what I guess, but I bet that a DocumentFactory instance is retreived via a J2EE mechanism which returns an instance of the version A. Or this instance must be used within version B of dom4j which causes a ClassCastException.

           

          Which versions of dom4j are you using (the one within your application, and the one deployed as a module) ? Can you also find the stackstrace of the original ClassCastException (which causes the DocumentException).

           

          I'd recommend you to use the same version of dom4j, if you need a more recent version, you might try to update the version within the module (take care then you might run with oher issues), if you need an older version: just refactor your application !

          • 2. Re: JBoss 7 Class Loading
            sbourguiba

            Hi,

             

            Sorry for the delay, I use dom4j-1.6.1 the same version uses in jboss7.1 and I change the server jar with mine and it is the same exception.

            For the stackstrace it's the original ClassCastException.

            What do you think?

            • 3. Re: JBoss 7 Class Loading
              ntsankov

              My guess is that it is the same class, loaded by another classloader.

              Anyway, can anyone shed some light on the matter?

              • 4. Re: JBoss 7 Class Loading
                smigielski

                Hi, I have exactly the same issue. Have you found any reasonable solution?

                • 5. Re: JBoss 7 Class Loading
                  ctomc

                  Did you try to remove dom4j jar from your application and import it via manifest or jboss-deployment-structure.xml?

                  • 6. Re: JBoss 7 Class Loading
                    areakbaby

                    Hi,

                     

                    I got the same problem.The hibernate want to exclusion dom4j,but the poi.jar need dom4j to read excel2007.

                     

                    Maven with hibernate:

                    <dependency>
                       <groupId>org.hibernate</groupId>
                       <artifactId>hibernate-core</artifactId>
                       <version>4.0.1.Final</version>
                       <exclusions>
                        <exclusion>
                         <groupId>dom4j</groupId>
                         <artifactId>dom4j</artifactId>
                        </exclusion>
                       </exclusions>
                    </dependency>

                     

                    Maven with poi:

                    <dependency>
                       <groupId>org.apache.poi</groupId>
                       <artifactId>poi-ooxml</artifactId>
                       <version>3.9</version>
                       <exclusions>
                        <exclusion>
                         <groupId>dom4j</groupId>
                         <artifactId>dom4j</artifactId>
                        </exclusion>
                       </exclusions>
                      </dependency>

                     

                    Do you fix you bug,please tell me?

                    Thank you so much.

                     

                    Best Regards;

                    Areak.

                    • 7. Re: JBoss 7 Class Loading
                      areakbaby

                      Hi All,

                       

                      Unbelievable,I fixed the problem by myself.

                       

                      add:

                      <subsystem xmlns="urn:jboss:domain:ee:1.0">
                                  <global-modules>
                                      <module name="org.dom4j" slot="main"/>
                                  </global-modules>
                      </subsystem>

                       

                      in standalone.xml,and the project work well.

                       

                      呵呵……感谢这里的老外们。

                      • 8. Re: JBoss 7 Class Loading
                        ouadi_dev

                        Thanks it works well.