1 Reply Latest reply on Aug 4, 2009 12:55 PM by peterj

    ClassLoading Problem

    stemccann

      I have been looking at a problem which has me completely stumped. I know there is a lot of information out there regarding ClassLoading and I have read most of it. Anyway here is my problem :

      I am using jboss 4.2.1, I had an EAR containing an EJB file and a WAR file.

      When I deployed this it all worked fine, but, as the EAR was getting a bit big I decided to deploy the EJB and WAR files separately. I applied the relevant changes to allow the WAR to access the EJB remotely as this is now a separate application, this worked for any JSP that didn't have a reference to a shared JAR.

      I then removed the JAR from the WAR as it seemed that having two versions (though identical) created a problem. I assumed that this was to do with there being two ClassLoaders. Again this seemed to solve some of the problems which brings me to the crux of the problem.

      I have a JAR that is shared between the EJB and the WAR, when I access the via the EJB there is no problem as the JAR is packaged with the EJB.
      When I access via the WAR I get strange behaviour, some of the classes are accesed ok (possibly the ones that the EJB has already accessed) but others are not accessable and give a Servlet.service() for servlet jsp threw exception
      java.lang.ClassNotFoundException: error then the page is accessed (when other pages have already accessed the package sucessfully ?????).

      I am sort of convinced that the problem is something to do with the two classloaders but I can't seem to resolve the problem.

      Any help would be really appriciated as I am losing the will to live. Surely it isn't this difficult or maybe I am an idiot.

        • 1. Re: ClassLoading Problem
          peterj

          Without knowing more details (exactly where the classes are located, and what the class was not found) it is hard to say.

          But in general if you package a class within a WAR file, only other classes within that WAR file have visibility to those classes. If a class in, for example, the EJB JAR attempts to access a class within the WAR you will get a CNFE. (I cannot tell if that is what you are running into or not.)