5 Replies Latest reply on Jan 14, 2009 5:32 AM by bemar

    java2ParentDelegation does not work

    bemar

      Hi,

      I've read the article http://www.jboss.org/community/docs/DOC-9288 about java2ParentDelegation to controll the
      class loader and "force" it to use the libraries from the application libs instead of the jboss libs.

      I've inserted the

      <?xml version="1.0"?>
      <!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
      <jboss-app>
       <loader-repository>
       Bemar:service=CronService
       <loader-repository-config>
       java2ParentDelegation=false
       </loader-repository-config>
       </loader-repository>
      
       <module>
       <service>Cron.sar</service>
       </module>
       <module>
       <service>Cron.jar</service>
       </module>
      </jboss-app>
      

      into my jboss-app.xml but jboss is using already the library from the jboss lib.

      I've constructed the following test case:

      In the constructor of my main class (MainClass.java) I will call:
       logger.info(new TestLoad().getTestLoadString());
      

      getTestLoadString() is a method of class TestLoad in an external jar "ClassLoadTest.jar". I have two versions of it:
       TestLoad_1.0.java
       public class TestLoad {
      
       public TestLoad() {
       }
      
       public String getTestLoadString(){
       return "1.0";
       }
      }
      

      TestLoad_2.0.java
       public class TestLoad {
      
       public TestLoad() {
       }
      
       public String getTestLoadString(){
       return "2.0";
       }
      }
      


      The 1.0 version is compiled directly into the ear file. The 2.0 version lies in the ...\server\default\lib directory.

      But in every case the 2.0 version is taken. JBoss does not matter about the settings of the loader-repository.

      Do I have do adjust further settings to prevent the parent lib loading?

      Thx for your help

      Greetings

      Ben

        • 1. Re: java2ParentDelegation does not work
          jaikiran

          Which version of JBossAS? And where exactly have you placed the jar file in the EAR? What does your application.xml look like?

          Furthermore, this entry in the jboss-app.xml, doesn't look right to me:

          <module>
           <service>Cron.jar</service>
           </module>
          


          What type of jar is the the Cron.jar? Just a jar file containing utility classes? You can place such jars in EAR/lib folder without having to make any entry in application.xml nor jboss-app.xml

          • 2. Re: java2ParentDelegation does not work
            bemar

             

            "jaikiran" wrote:
            Which version of JBossAS? And where exactly have you placed the jar file in the EAR? What does your application.xml look like?

            Its Jboss 4.2.2 GA.
            The TestLoad JAR is in the Cron.jar. The Cron.jar is in the ear.
            The posted xml is the jboss-app.xml or do you mean another xml?
            In the ear file in the meta-inf folder is a application.xml file but it has the same content like the jboss-app.xml.

            Furthermore, this entry in the jboss-app.xml, doesn't look right to me:

            <module>
             <service>Cron.jar</service>
             </module>
            


            Hmm. But it works ...

            What type of jar is the the Cron.jar? Just a jar file containing utility classes?

            In the cron.jar are all my classes, services and imported jars.

            You can place such jars in EAR/lib folder without having to make any entry in application.xml nor jboss-app.xml




            • 3. Re: java2ParentDelegation does not work
              bemar

              Does nobody else have a hint?

              Thx
              Ben

              • 4. Re: java2ParentDelegation does not work
                jaikiran

                Try this, add -verbose:class to the run.bat (or run.conf if you are using *nix OS) to the JAVA_OPTS section. Then start your server (you will have to redirect the output to a file to avoid very verbose classloading logs). Then access your application when server is started and look at the logs. The logs will give you the information about which jar is being used to load the class.

                • 5. Re: java2ParentDelegation does not work
                  bemar

                  Got the following loggings:


                  11:20:40,514 DEBUG [SARDeployer] deployed classes for file:/C:/Programme/jboss-4.2.2.GA/server/default/lib/TestLoad_2.0.jar
                  ...
                  ...
                  11:20:42,139 DEBUG [RepositoryClassLoader] Added url: file:/C:/Programme/jboss-4.2.2.GA/server/default/lib/TestLoad_2.0.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@384065{ url=null ,addedOrder=2}
                  ...
                  ...


                  Nothing about TestLoad_1.0.jar which is directly in the Cron.jar