1 2 Previous Next 15 Replies Latest reply on Aug 13, 2012 3:59 AM by karan.kap

    Jboss 7 class-loading

    colective

      Hi,

       

      i managed to solve most of problems with EAR installation discussed in https://community.jboss.org/thread/195810?tstart=30

       

      now i have few question regarding visibillity between jars and wars in ear file, log4j and lib directories

       

      myear:

           |----libs (xml-apis-2.6.2.jar, commons-logging-1.1.1.jar, commons-codec-1.4.jar, castor-1.3.2-xml.jar)

           |----oracle (oracle jars)

           |----config (config.jar)

           |----log4 (log4j-1.2.16.jar)

           |

           |----jar1.jar

           |----jar2.jar

           |----jar3.jar

           |----config.jar.jar (moved from config directory) (com.web.conf.config.xml.XMLModule)

           |

           |---- webapp1.war (com.web.webapp.cbs.plugins.CBSPlugin)

           |---- webapp2.war (com.web.webapp.authentication.servlets)

       

      my problem is that i cannot change ear structure and move all jars to lib dir (this is Websphere application that cannot be changed)

       

      all jars are simple jars (no ejb)

       

      jar1.jar uses classes from jar2.jar, jar3.jar and jar4.jar and i can solve this by adding in jboss-deployment-structure.xml in EAR/META-INF

       

      config.jar is moved from config dir because i dont know how to tell in jboss-deployment-structure.xml to include jar file which is not in / or in lib directory

       

      <jboss-deployment-structure>

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

          <deployment>

          <dependencies>

              <module name="deployment.myear.ear.jar1.jar" />

              <module name="org.apache.xerces" export="true" />

              <module name="org.apache.log4j" />

          </dependencies>

          </deployment>

              <module name="deployment.myear.ear.jar1.jar" slot="1.0"  >

          <resources>

              <resource-root path="jar2.jar"/>

              <resource-root path="jar3.jar"/>

              <resource-root path="config.jar"/>

          </resources>

              <dependencies>

              <module name="org.apache.xerces"/>

          </dependencies>

          </module>

      </jboss-deployment-structure>

       

       

      but problem rises when webapp1.war tries to load classes from jar1 and for that i receive java.lang.ClassNotFoundException

       

      how can i adopt jboss-deployment-structure.xml to make visible classes to war files?

       

      this is error from log files (i can send private message with real jar files, ear structure and error)

       

      00:51:44,219 ERROR [] (MSC service thread 1-7) Exception during initialization of module cbsPlugin(class=com.web.webapp.cbs.plugins.CBSPlugin): java.lang.RuntimeException: Error during creation of Module cbsPlugin(class=com.web.webapp.cbs.plugins.CBSPlugin

              at com.web.conf.config.xml.XMLModule.createModule(XMLModule.java:230) [config.jar:]

              at com.web.conf.config.Configuration.initModule(Configuration.java:573) [config.jar:]

              at com.web.conf.config.Component$Base.init(Component.java:48) [config.jar:]

              at com.web.conf.config.ActiveComponent$Base.start(ActiveComponent.java:217) [config.jar:]

              at com.web.webapp.authentication.servlets.InitServlet.init(InitServlet.java:64) [classes:]

              at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

              at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.10.Final.jar:]

              at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.10.Final.jar:]

              at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.10.Final.jar:]

              at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.10.Final.jar:]

              at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_27]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_27]

              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_27]

      Caused by: java.lang.ClassNotFoundException: com.web.webapp.cbs.plugins.CBSPlugin from [Module "deployment.myear.ear.jar1.jar:1.0" from Service Module Loader]

              at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

              at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

              at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

              at com.ibm.asmpcee.config.xml.XMLModule.createModule(XMLModule.java:191) [config.jar:]

              ... 15 more

       

       

       

      second question is regarding lib directories

       

      how can i add nondefault lib directories to be used as default?

       

      ear don't have ear/lib  it has ear/lib, ear/oracle, ear/config, ear/log4j with lib files which cannot be changed as i said..

       

      and last question regarding log4j

       

      how can i config jboss 7 not to use default jboss logger?

      we need to use log4j

       

      i have these error in log

       

      12:10:01,953 INFO  [] (MSC service thread 1-8) Using platform default MBean server org.jboss.as.jmx.PluggableMBeanServerImpl@199d4a86 with default domain: DefaultDomain

      12:10:01,957 DEBUG [] (MSC service thread 1-8) preRegister called. Server=com.sun.jmx.mbeanserver.JmxMBeanServer@30296f76, name=log4j:logger=

      12:10:01,958 ERROR [stderr] (MSC service thread 1-8) LoggerRepository(org.jboss.logmanager.log4j.BridgeRepository@61181c24)

      12:10:01,958 ERROR [stderr] (MSC service thread 1-8) logrep.getCurrentLoggers() is empty

      12:10:01,958 ERROR [stderr] (MSC service thread 1-8) logrep.getCurrentCategories() is empty

      12:10:01,958 ERROR [stderr] (MSC service thread 1-8) rootLogger(org.jboss.logmanager.log4j.BridgeLogger@75dfb148)

      12:10:01,959 ERROR [stderr] (MSC service thread 1-8) aaaLogger(org.jboss.logmanager.log4j.BridgeLogger@30f02a6d)

       

      and as outcome, everything is logged only to stderr and not in application log files

       


      thanks

      Tomislav

        • 1. Re: Jboss 7 class-loading
          sebbay

          Hey Tomislav,

           

          Have you found a solution for your problems depending on log4j?

           

          Best regards,

          Sebastian

          • 2. Re: Jboss 7 class-loading
            colective

            Hi,

             

            yes, problem is solved with exclusions in jboss-structure xml

             

            thank you

            tomislav

            • 3. Re: Jboss 7 class-loading
              sebbay

              Can you please post the special log4j part of your jboss-structure.xml?

              • 4. Re: Jboss 7 class-loading
                colective

                <jboss-deployment-structure>

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

                   <deployment>

                     <exclusions>

                       <module name="org.apache.log4j" />

                     </exclusions>

                   </deployment>

                 

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

                    <exclusions>

                       <module name="org.apache.log4j" />

                    </exclusions>

                        <dependencies>

                          <module name="deployment.YourEarFile.ear.Log4j" />

                        </dependencies>

                       </sub-deployment>

                    

                     <module name="deployment.YourEarFile.ear.Log4j" >

                          <resources>

                                 <resource-root path="libs/log4j-1.2.15.jar" >

                                 </resource-root>

                          </resources>

                     </module>

                </jboss-deployment-structure>

                 

                regards

                Tomislav

                • 5. Re: Jboss 7 class-loading
                  sebbay

                  Thanks!

                   

                  I thought adding a section with module excludes to the deployment section is enough:

                   

                  <deployment>

                    <exclusions>

                      <module name="org.apache.log4j" />

                    </exclusions>

                  </deployment>

                   

                  But your file looks like I have to that for each sub-deployment.

                  Am I correct with this?

                  • 6. Re: Jboss 7 class-loading
                    colective

                    im not sure that this is fixed in Jboss 7.1.1 but for now you need to add this in every sub-depoyment

                     

                    t.

                    • 7. Re: Jboss 7 class-loading
                      sebbay

                      Thank you! I think my problem is resolved now!

                       

                      Regards

                      sebbay

                      • 8. Re: Jboss 7 class-loading
                        sbourguiba

                        Hi Sebastien,

                         

                        I have ClassCastException when i try to deploy my EAR (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).

                        This is my jboss-deployment-structure.xml:

                         

                        <jboss-deployment-structure>

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

                                  <deployment>

                                            <exclusions>

                                                      <module name="org.dom4j" slot="main"/>

                                            </exclusions>

                                  </deployment>

                        </jboss-deployment-structure>

                         

                        What do you think?

                         

                        Regards

                        • 9. Re: Jboss 7 class-loading
                          sebbay

                          I think you have to set this exclusion for each subdeployment:

                           

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

                              <exclusions>

                                 <module name="org.dom4j" />

                              </exclusions>

                            </sub-deployment>

                           

                          Otherwise, your subdeployments will take the jboss dom4j classes.

                           

                          Regards,

                          Sebastian

                          • 10. Re: Jboss 7 class-loading
                            sbourguiba

                            I added my subdeployments and it's the same problem.

                            jboss-structure.xml:

                            <jboss-deployment-structure>

                            <ear-subdeployments-isolated>true</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:

                             

                            09:04:56,401 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) 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

                             

                            Regards

                            • 11. Re: Jboss 7 class-loading
                              karan.kap

                              Could anyone please post the exact deployment structure to be used for getting log4j to work. I am using the following:

                               

                              <jboss-deployment-structure>

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

                                  <deployment>

                                      <exclusions>

                                          <module name="org.apache.log4j" />

                                      </exclusions>

                                  </deployment>

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

                                      <exclusions>

                                          <module name="org.apache.log4j" />

                                      </exclusions>

                                      <dependencies>

                                          <module name="deployment.Test.ear.Log4j" />

                                      </dependencies>

                                  </sub-deployment>

                                  <module name="deployment.Test.ear.Log4j">

                                      <resources>

                                          <resource-root path="lib/log4j-1.2.13.jar">

                                          </resource-root>

                                      </resources>

                                  </module>

                              </jboss-deployment-structure>

                               

                              I have tried with ear-subdeployments-isolated = true as well, but that also didn't work. The jboss-deployment-structure.xml is placed under EAR->META-INF folder and log4j.xml is placed in the lib folder.

                               

                              Am I missing anything here?

                               

                              Thanks,

                              Karan

                              • 12. Re: Jboss 7 class-loading
                                colective

                                Hi,

                                 

                                in case that you have one war file and that every jar is in /lib directory in root of ear

                                 

                                <jboss-deployment-structure>
                                    <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
                                        <deployment>
                                            <exclusions>
                                                <module name="org.apache.log4j" />
                                            </exclusions>
                                        <dependencies>
                                    <module name="deployment.Webapp.ear.WEB.war" />
                                        </dependencies>
                                            <resources>
                                            </resources>
                                        </deployment>

                                <sub-deployment name="Webapp.ear.WEB.war">
                                                <exclusions>
                                                        <module name="org.apache.log4j" />
                                                </exclusions>
                                    </sub-deployment>
                                </jboss-deployment-structure>

                                 

                                <ear-subdeployments-isolated>false</ear-subdeployments-isolated> - put this in standalone.xml

                                 

                                aslo, your application.xml should be JEE6 compatible

                                example:

                                 

                                <?xml version="1.0" encoding="UTF-8"?>

                                <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">

                                <display-name>Webapp.ear</display-name>

                                <initialize-in-order>true</initialize-in-order>

                                 

                                 

                                regards

                                tomislav

                                • 13. Re: Jboss 7 class-loading
                                  karan.kap

                                  Thanks Tomislav for your reply. I have done the steps that you listed above, however, it still doesn't work. My EAR file contains EJBs (jar) and there is no WAR. EJB's use some other jar files that are present in the lib directory.

                                   

                                  Could you please let me know where to place log4.xml. I have tried it at the root level of the EAR, in META-INF directory as well.

                                   

                                  Regards,

                                  Karan

                                  • 14. Re: Jboss 7 class-loading
                                    remyvrs

                                    hello,

                                     

                                    i also haven't got the ear to work with my log4j.xml inside jboss as 7.1.1

                                    i have tried the upper advices, and they really seem to be the solution, yet i believe there is something missing ...

                                     

                                    Karan, did you get it to work ?

                                    is there anything else that should be done ?

                                     

                                    Thanks in advance

                                    Best Regards,

                                    Remus

                                    1 2 Previous Next