8 Replies Latest reply on Jul 14, 2006 3:06 AM by jaikiran

    Why loading the class in EJB jar rather than the one in war

    bennyckp

      Hi everyone,

      This question is about the class loader config in JBoss.
      I am currently deploying a EJB jar and a war in JBoss 4.0.3SP1.
      They are mdb.jar and app.war and are placed in the server/default/deploy folder separately.

      In the mdb.jar, I have a ClassA.class, i.e.
      mdb
      |_ ClassA.class (version 1)
      |_ META-INF

      In the app.war, I also have a ClassA.class but it contains some system out in this version, i.e.
      app
      |_ WEB-INF
      | |_ classes
      | |_ClassA.class (version 2 w/ system out)
      |_ ...
      When I startup my JBoss, I don't know why the web application uses the ClassA in the mdb.jar which has no system out?

      My Question is:
      1. Do the jar and the war share a common class loader ?
      2. After I've read the doc about JBoss setting, I config the jboss-web.xml in the app.war as follow but the problem still exists.

      <jboss-web>
       <class-loading java2ClassLoadingCompliance="false">
       <loader-repository>
       com.cherrypicks:loader=chs.war
       <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
       </loader-repository>
       </class-loading>
       </jboss-web>

      Even though I redeploy the app.war, it still loads the ClassA in mdb.jar.
      Can anybody explain it ?

      My jboss tomcat setting is like below..
      <attribute name="Java2ClassLoadingCompliance">false</attribute>
      <attribute name="UseJBossWebLoader">false</attribute>


      3. I want different deployments use their own classes in jar/war and don't let them to use the classes (with same name) in other deployment, i.e. separate class loader. How can I do that ?

      Thanks,
      Benny Chan

        • 1. Re: Why loading the class in EJB jar rather than the one in
          jaikiran

           

          My jboss tomcat setting is like below..


          <attribute name="Java2ClassLoadingCompliance">false</attribute>
           <attribute name="UseJBossWebLoader">false</attribute>


          I believe, this should be:

          <attribute name="Java2ClassLoadingCompliance">true</attribute>
          <attribute name="UseJBossWebLoader">true</attribute>


          Try it out.



          • 2. Re: Why loading the class in EJB jar rather than the one in
            bennyckp

            Thanks, jaikiran.
            But it still don't work.

            Could you tell me what is the purpose to config like this ?

            <attribute name="Java2ClassLoadingCompliance">true</attribute>
            <attribute name="UseJBossWebLoader">true</attribute>


            How can I use separate class loaders in separate deployments?

            Thanks.

            • 3. Re: Why loading the class in EJB jar rather than the one in
              jaikiran

               

              How can I use separate class loaders in separate deployments?


              There is very good information about this on the Wiki pages. Here are the links to the same:

              http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration

              http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossClassLoadingUseCases

              http://wiki.jboss.org/wiki/Wiki.jsp?page=EnableClassloaderLogging


              Could you tell me what is the purpose to config like this ?
              <attribute name="UseJBossWebLoader">true</attribute>


              Have a look at:
              http://jira.jboss.com/jira/browse/JBAS-1691

              And looking at this JIRA and the earlier links that i mentioned, i guess you were correct in mentioning

              <attribute name="UseJBossWebLoader">false</attribute>



              • 4. Re: Why loading the class in EJB jar rather than the one in
                jaikiran

                I went through your first post once again and was a bit confused by the statement:

                When I startup my JBoss, I don't know why the web application uses the ClassA in the mdb.jar which has no system out


                Can you explain as to who is invoking this ClassA? Is it JBoss or it from some other class? Just trying to understand as to why JBoss would invoke that class when deployment is going on, assuming ClassA is just a POJO class(or is it not?)





                • 5. Re: Why loading the class in EJB jar rather than the one in
                  bennyckp

                  Sorry to confuse you.
                  I should say "After I startup my JBoss,.."

                  ClassA is invoked by a JSP in app.war rather than JBoss.

                  Thanks for your useful links first.
                  As I mentioned before, I've read all these before this post.
                  To my understanding, do you suggest the following config ?

                  <attribute name="Java2ClassLoadingCompliance">true</attribute>
                  <attribute name="UseJBossWebLoader">false</attribute>


                  As I am back home, I will try this tomorrow.
                  Thanks for your help again !



                  • 6. Re: Why loading the class in EJB jar rather than the one in
                    jaikiran

                     

                    To my understanding, do you suggest the following config ?


                    <attribute name="Java2ClassLoadingCompliance">true</attribute>
                    <attribute name="UseJBossWebLoader">false</attribute>


                    NO. Let it be:

                    <attribute name="Java2ClassLoadingCompliance">false</attribute>
                    <attribute name="UseJBossWebLoader">false</attribute>


                    With this setting and with Classloader logging enabled:

                    http://wiki.jboss.org/wiki/Wiki.jsp?page=EnableClassloaderLogging

                    post the classloader logs. That will surely help in understanding, whats going on internally.





                    • 7. Re: Why loading the class in EJB jar rather than the one in
                      bennyckp

                      Please refer the scenario and the config in my first post.

                      In the jmx-console, I invoke the getPackageClassLoaders() of the loader with the param=ClassA.

                      It returns like that

                      [org.jboss.mx.loading.LoadMgr3$PkgClassLoader@bb365d
                      {ucl=org.jboss.mx.loading.HeirarchicalLoaderRepository3$CacheClassLoader@4129e3
                      { url=null ,addedOrder=0} order=1},

                      org.jboss.mx.loading.LoadMgr3$PkgClassLoader@ee37f2
                      {ucl=org.jboss.mx.loading.UnifiedClassLoader3@10cf62
                      { url=file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp44379mdb.jar ,addedOrder=41} order=2},

                      org.jboss.mx.loading.LoadMgr3$PkgClassLoader@19b07e9
                      {ucl=org.jboss.mx.loading.UnifiedClassLoader3@24fe6b
                      { url=null ,addedOrder=0} order=3}
                      ]


                      My question is:
                      1. What is the meaning of "url=null"?
                      2. Does the "order=1", "order=2"... determine the class loading order?
                      3. ClassA is loaded from mdb.jar instead of the app.war. But why?

                      FYI, I can see the package of ClassA (say com.XXX) only appears once in the ucl log.

                      ...
                      [48531,UnifiedClassLoader,main] New jmx UCL with url file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp44379mdb-1.3.jar
                      [48531,RepositoryClassLoader,main] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@1da669c, cl=org.jboss.mx.loading.UnifiedClassLoader3@10cf62{ url=file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp44379mdb-1.3.jar ,addedOrder=0}
                      [48531,RepositoryClassLoader,main] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@1da669c, cl=org.jboss.mx.loading.UnifiedClassLoader3@10cf62{ url=file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp44379mdb-1.3.jar ,addedOrder=0}
                      [48531,UnifiedLoaderRepository3,main] Adding org.jboss.mx.loading.UnifiedClassLoader3@10cf62{ url=file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp44379mdb-1.3.jar ,addedOrder=0}
                      [48547,ClassLoaderUtils,main] Indexed pkg: com.XXX, UCL: org.jboss.mx.loading.UnifiedClassLoader3@10cf62{ url=file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp44379mdb-1.3.jar ,addedOrder=41}
                      [48547,ClassLoaderUtils,main] Indexed pkg: com.XXX.YYY, UCL: org.jboss.mx.loading.UnifiedClassLoader3@10cf62{ url=file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp44379mdb-1.3.jar ,addedOrder=41}
                      ...


                      It's difficult to post the class loading log here as it is too large. Could you suggest what thing I should post here?

                      Thanks.

                      • 8. Re: Why loading the class in EJB jar rather than the one in
                        jaikiran

                         

                        FYI, I can see the package of ClassA (say com.XXX) only appears once in the ucl log.


                        Just to make sure that the packaging of your app.war and mdb.jar is correct, can you run the following commands from the prompt and post the output:

                        jar -tf app.war


                        jar -tf mdb.jar


                        This will display the contents of your archive.

                        Alternately, if your application is not a huge one and if mailing your application is not a issue, you can mail me the same to jai_forums2005 at yahoo.co.in. Let me try it out