1 Reply Latest reply on Aug 7, 2007 6:20 AM by lucdew

    Classloading problem (sar within ear)

    lucdew

      Hi,

      i have experienced some issues with classloading in Jboss.

      Actually, here's how my ear is packaged:

      myapp.ear:
      ---->init.sar
      ---->mylib.jar

      In my sar package, i need to load a resource which is packaged in mylib.jar

      If i declare a loader repository the resource can not been seen.

      I added in the init.sar 's manifest.mf file a dependency on mylib.jar by declaring
      a class-path entry.

      I declared the java modules in the application.xml like this:

      <module>
       <java>mylib.jar</java>
       </module>


      and in my jboss-app.xml:

      <loader-repository>
       com.myapp:loader=testapp
       </loader-repository>
       <module>
       <service>init.sar</service>
       </module>



      I even tried the different options:

      <loader-repository>
       com.myapp:loader=testapp
       <loader-repository-config>
       java2ParentDelegation=false
       </loader-repository-config>
       </loader-repository>


      and with java2ParentDelegation setting to true.

      Even after reading the wiki and jboss documentation i am not sure to understand
      which classloaders are created for my ear and the strategy they use to load
      classes (parent delegation or not).

      For me, by declaring a loader-repository for my ear it only isolates classes
      and libraries of my ear from the other ear but the classloader is unified (flat).
      Is this correct ?

      How could i deal with this issue ?

      Thanks in advance,
      Luc

        • 1. Re: Classloading problem (sar within ear)
          lucdew

          Hi,

          i have tried to debug the issues with classloader but one 's still remaining.

          My application is packaged like this:

          myapp.ear
          --> spring.jar
          --> mysar.sar
          --> myjar.jar

          I declared spring.jar and myjar.jar in application.xml as Java modules (ex: spring.jar)

          In mysar.sar i displayed information of the current classloader and here's what i get:

          11:58:54,765 INFO [DeployerListenerService] Current classloader = org.jboss.mx.
          loading.UnifiedClassLoader3@10d16b{ url=file:/D:/applications/jboss-4.0.
          5.GA/server/default/deploy/myapp.ear/ ,addedOrder=40}


          and if i execute the following code:
          Enumeration<URL> resourcesEnum = this.getClass().getClassLoader().getResources("beanRefContext.xml");


          the classloader find the resource beanRefContext.xml which is packaged in myjar.jar. It works as expected.

          The problem is Spring library executes almost the same code in the PathMatchingResourcePatternResolver class it executes:
          Enumeration resourceUrls = getClassLoader().getResources(path);

          where path is "beanRefContext.xml"
          and the getClassLoader() returned in debug mode has a path attribute of:
          /D:/applications/jboss-4.0.5.GA/server/default/conf/

          and therefore is unable to see the beanRefContext.xml file packaged in my ear.

          Note that i configured in my ear a loader repository :
          <loader-repository>
           test.com:loader=myapp
          </loader-repository>


          I don't understand why the classloader retrieved in Spring is the one associated with the universalrepository3 ? and not the HeirarchicalLoaderRepository3 of my ear???

          I checked the CLASSPATH and my Jboss installation to see if there were Spring classes elsewhere and no the only Spring classes are in the spring.jar of myapp.ear.

          Please i need help.