1 Reply Latest reply on Aug 12, 2009 12:06 PM by jaikiran

    EAR classloading and Class-Path in ejb jar file MANIFEST.MF

    rolfarne

      When trying to port an EAR wrapped application from JBoss AS 4.2.2 to 5.1.0, I am struggling with classloading issues:

      Context

      The EAR have one ejb (EJB 2) module and several web modules.

      It also contains a set of library jar files that are shared by the modules. These jar files are referenced in the MANIFEST.MF file in the modules as needed, but the jar files are also dependent on each other (e.g. A.jar used classes from B.jar)

      The jboss-app.xml for the EAR is configured with a loader-repository element to enforce class loader isolation. Besides that, I use the default class loading configuration in the 'default' server configuration.

      Problem

      The typical scenario when things fail with a NoClassDefFoundError is as follows:

      1) A web application invokes Acme.class from Foo.jar in the EAR (jar referenced in the Class-Path of the manifest of the war)

      2) Foo.jar is also referenced in the Class-Path of the manifest of the ejb jar file.

      3) Acme.class needs to access Util.class in Bar.jar in the EAR. Now. Bar.jar is referenced in the Class-Path of the manifest of the war, BUT NOT in the Class-Path of the manifest of the ejb jar).

      4) A NoClassDefFoundError for Util.class is thrown.

      However, if Bar.jar is added to the Class-Path of the manifest of the ejb jar, the class is found.

      When looking at the class loaders in the JMX console, I can see that when Bar.jar is added to the Class-Path of the manifest of the ejb jar, packages from that jar shows up the exported packages of the EAR class loader, while they show up in the war class loader when it is NOT added to the Class-Path of the manifest of the ejb jar. I guess this explains the NoClassDefFoundError, but I wonder why the manifest of the ejb jar affects which classes are loaded by the EAR class loader?

      As it is now, I have to jars for web applications to the Class-Path of the ejb, which feels unnatural and confusing for other developers. Am I missing something here? Is there some configuration option I can use to eliminate these errors?

        • 1. Re: EAR classloading and Class-Path in ejb jar file MANIFEST
          jaikiran

          Place all your simple library jar files (NOT the EJB jars) in the EAR/lib folder. And place the EJB jar and the WAR at the root of the EAR. The jars in EAR/lib will then be available to all the components in the EAR. You won't need the MANIFEST.MF ClassPath entries. An example:

          myapp.ear
           |
           |
           |--- META-INF
           | |--- application.xml
           |
           |
           |--- lib
           | | --- xyz.jar (plain jar files)
           | | --- more plain jar files
           |
           |
           |--- ejbjar1.jar
           |
           |--- ejbjar2.jar
           |
           |--- myapp.war
           |
           |---