5 Replies Latest reply on May 6, 2003 3:59 PM by Tim Squires

    Classloader problem

    Tim Squires Newbie

      Hi, I have two web apps in an ear file, each have a set of classes that are dynamically loaded (reflection) when needed.

      If I access app 1 app then try the other, app 2 cannot find it's classes.

      Trying it the other way round (after a reboot), i.e. app 2 then access app 1 the app that was accessed second (app 1 in this case) cannot load it's classes but app 2 was OK!

      Is there a restriction in the class loader for multiple web apps in an ear?

      Thanks for your help.

        • 1. Re: Classloader problem
          Tim Squires Newbie

          p.s. an example stack track is

          java.lang.ClassNotFoundException: net.tqweb.actions.openProject
          at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
          at org.jboss.mx.loading.UnifiedClassLoader.findClass(UnifiedClassLoader.java:401)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
          at org.jboss.mx.loading.UnifiedClassLoader.loadClassLocally(UnifiedClassLoader.java:242)
          at org.jboss.mx.loading.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:114)
          at org.jboss.mx.loading.LoadMgr.nextTask(LoadMgr.java:281)
          at org.jboss.mx.loading.UnifiedClassLoader3.loadClass(UnifiedClassLoader3.java:181)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
          at net.truetrue.util.servlets.actions.ActionFactory.getAction(Unknown Source)
          at net.truetrue.util.servlets.actions.ActionServlet.service(Unknown Source)

          • 2. Re: Classloader problem
            Ben Litchfield Newbie

            you want to put all common files in a separate jar file and put that in your ear. Then create a MANIFEST.MF file and put it in each war file, like so

            Class-Path: commonfiles.jar
            Class-Path: commonfiles.jar

            • 3. Re: Classloader problem
              Tim Squires Newbie

              Thanks Ben. Forgot about the manifest. Would you mind having a look at the following and see why it's not picking up the classpath from the new MAINIFEST.MF?


              Is the current structure of the ear file. All MANIFEST.MF's have the same content:

              Manifest-Version: 1.0
              Ant-Version: Apache Ant 1.5.3
              Created-By: 1.4.1_01-b01 (Sun Microsystems Inc.)

              Name: Maintbook
              Class-Path: maintbook-common.jar utils.jar

              I have taken the maintbook-common.jar out of the external path to make the ear closed. Now the ejb's will not deploy because the class loader does not load the maintbook-common.jar. It seems the same for the wars (but I can't test them properly without the EJB's)

              Thanks for your help, Tim.

              • 4. Re: Classloader problem
                Raja Master

                I would try removing the MANIFEST.MF from all the web archives and have the MANIFEST.MF in your ejb archive alone. If you look at the classloader hierarchy, your ejb will be loaded first and then the wars within an ear(Thats how ive seen in weblogic). So your EJBs shud hve access to maintbook-common.jar and your wars can pick it from there.


                • 5. Re: Classloader problem
                  Tim Squires Newbie

                  Thanks Raj
                  I've tried that but the common classes are not loaded by the web apps if the MANIFEST.MF file for each war has the correct class-path.

                  Which brings me round to the original problem.....

                  The jars are definitly being loaded by the classloader, the problem occurs only on accessing a second war from the same ear.

                  It does not matter which web app I access first, that one allways loads it's classes correctly. On visiting the second web app, the classes that I have seen loaded on previous occasions are not found. ????

                  It's bound to be something really simple that I've missed over these last 5 hours....