3 Replies Latest reply on May 4, 2006 3:43 PM by bdecoste

    EJB3 access and classloader

    yeyuancn

      I have an impression that in Tomcat, each war file is deployed by its own classloader, so a class in one war file can't see the class in another war file, is this correct?
      I am assuming the same architecture with JBoss server, at runtime one class can not see another class if they belong to two different .ejb3 files. However after some tests, seems Jboss is using a single classloader for all .ejb3 files. Is that true? (I am using Jboss 4.0.3SP1 + EJB3_RC6)

      Here is my test case:
      EJB1:
      Define a staleless session bean with name "CalculatorBean" which implements interface "Calculator"

      EJB2:
      Define another staleless session bean containing the following code:

      code:
      --------------------------------------------------------------------------------

      Calculator calculator = (Calculator) ctx.lookup("CalculatorBean/local");

      --------------------------------------------------------------------------------



      Since EJB2 file doesn't contain any class with name "Calculator", I was assuming it will throw ClassNotFoundException at runtime. But it turns out everything works fine in EJB2. So I guess the session bean in EJB2 can access classes in EJB1 directly, is that true?

        • 1. Re: EJB3 access and classloader
          bdecoste

          Unless you specify otherwise via the <loader-repository> element in jboss.xml, all classes in .jar (or .ejb3) files will be loaded into the same root classloader repository. You can use the <loader-repository> element to create child repositories per deployment - classes loaded into child repositories will not be visible outside of the particular deployment.

          • 2. Re: EJB3 access and classloader
            yeyuancn

            Is this a recent change (requirement), or is it always like this for Jboss4 +EJB3?

            • 3. Re: EJB3 access and classloader
              bdecoste

              I've done a little research - JBoss 4.x isolates war classes using the Tomcat classloader. To use the JBoss classloader for web deployments, you need to configure Tomcat to use the JBoss classloader. In deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml, set the UseJBossWebLoader attribute to true.