8 Replies Latest reply: May 23, 2013 3:05 PM by jtahlborn RSS

    Someting I can't explain regarding ClassNotFoundException

    1007187
      Hello everyone,

      Something that I don’t understand, knowing that a class is defined by its classloader and its FQN ….

      I have a servlet in Ear1. This servlet performs a lookup on an ejb1 located in Ear2 (both ears are located in the same JVM eg same managed instance in Weblogic environment) and calls a method which throws a RuntimeException which embeds a checked exception (MyException) located in ear2 => no MyException ClassNotFoundException raised in the servlet

      Now, I deploy ear1 on managed 1 and ear2 on managed2 (Weblogic environment), same call and I get a MyException ClassNotFoundException in the servlet.

      Any explanation ?
      Do you know why ?

      Best Regards.
        • 1. Re: Someting I can't explain regarding ClassNotFoundException
          jtahlborn
          1004184 wrote:
          Hello everyone,

          Something that I don’t understand, knowing that a class is defined by its classloader and its FQN ….

          I have a servlet in Ear1. This servlet performs a lookup on an ejb1 located in Ear2 (both ears are located in the same JVM eg same managed instance in Weblogic environment) and calls a method which throws a RuntimeException which embeds a checked exception (MyException) located in ear2 => no MyException ClassNotFoundException raised in the servlet
          are you using a local or remote interface? does weblogic have an option to avoid serialization for calls within the jvm? my guess is that MyException is not going through serialization when the call is made within the same jvm and therefore no ClassNotFoundException is raised.
          Now, I deploy ear1 on managed 1 and ear2 on managed2 (Weblogic environment), same call and I get a MyException ClassNotFoundException in the servlet.
          i assume you are expecting this situation.
          • 2. Re: Someting I can't explain regarding ClassNotFoundException
            1007187
            Hello,

            >
            Are you using a local or remote interface? does weblogic have an option to avoid serialization for calls within the jvm? my guess is that MyException is not >going through serialization when the call is made within the same jvm and therefore no ClassNotFoundException is raised.
            First, I am using a remote interface.
            Second between 2 ears in Weblogic there is always serialization. In order to avoid this you need to use at least shared libraries but this is not my environement. So it doesn't explain :-(

            FYI, I have perfomed a test on Glassfish and in the same JVM I don't get any ClassNotFoundException as well and I am pretty sure that there is serialization.
            I have performed a test on two glassfish instances: same result that in Weblogic I got a ClassNotFoundException which I don't get in I am in the same instance.

            Any explanation ?

            Best Regards.

            Edited by: 1004184 on May 22, 2013 10:24 AM
            • 3. Re: Someting I can't explain regarding ClassNotFoundException
              EJP
              Web-applications in the same JVM are loaded by different class loaders, so they can't see each other's classes. So an exception thrown by one produces a ClassNotFoundException in the other if the exception class isn't in both applications.
              • 4. Re: Someting I can't explain regarding ClassNotFoundException
                778462
                Hello,
                EJP wrote:
                Web-applications in the same JVM are loaded by different class loaders, so they can't see each other's classes. So an exception thrown by one produces a ClassNotFoundException in the other if the exception class isn't in both applications.
                Yes this is my understanding but the behavior I saw was not that :-(

                ear1, which contains the servlet calls an EJB method embedded in ear2 (so 2 different class loaders are involved there). The EJB method called, throws a RuntimeEXception which embeds a checked exception which doesn't exist in ear1. In this situation I got no NoClassNotFoundException exception which is not what I have excpected (reason of my post).

                So still haven't any explanation regarding the behavior I have seen :-(

                Best Regards.
                • 5. Re: Someting I can't explain regarding ClassNotFoundException
                  EJP
                  You are going to have to explain to us what the difference is between a class that isn't in both places and a class that isn't in both places.
                  • 6. Re: Someting I can't explain regarding ClassNotFoundException
                    gimbal2
                    Its a bit hard to follow, but I believe it is as simple as this.

                    Situation 1: two applications deployed on the same JVM and one application uses a class from the other; no classnotfound
                    Situation 2: two applications each deployed on their own isolated JVM ("managed1" and "managed2"); now a classnotfound occurs

                    If I'm correct then the difference in behavior is simply because Weblogic in situation 1 is in fact not configured to isolate classpaths so all applications are just thrown onto one big pile.
                    • 7. Re: Someting I can't explain regarding ClassNotFoundException
                      1007187
                      Hello,
                      gimbal2 wrote:

                      Situation 1: two applications deployed on the same JVM and one application uses a class from the other; no classnotfound
                      Situation 2: two applications each deployed on their own isolated JVM ("managed1" and "managed2"); now a classnotfound occurs
                      The situation you describe is absolutely right/correct: this is the behavior I have seen.

                      BUT: Weblogic and Glassfish, because I have observed the same behavior for those app servers, uses 2 different classloaders for each ears (eg ear1 and ear2). It's written in the spec and however in situation 1 no ClassNotFoundException :-(
                      So neither Weblogic nor Glassfish is configured to have the same class loader for ear1 and ear2.

                      Still no explanation :-(

                      Best Regards.
                      • 8. Re: Someting I can't explain regarding ClassNotFoundException
                        jtahlborn
                        did you confirm that the exception is actually being serialized between the 2 ears in the same jvm?