3 Replies Latest reply on Oct 14, 2004 6:40 AM by lindsay_h

    Classpath problems - Beans from one ear are using the JARs f

    lindsay_h

      Hello,

      I have one ear (hehe) - let's call it ear1 - that deploys fine and has lots of beans in it that do stuff and everything's fab.

      I have another ear - ear2 - that, when deployed on it's own, works fine too.

      But when I deploy them both, the beans from ear1 are using classes that are contained in a jar in ear2!

      Both ears contain jars that they need to do their business, and they both contain a jar called utility.jar. When I was making changes to the application that is ear1, I made changes to a few classes in utility.jar and rebuilt the whole lot into ear1. But I did not rebuild ear2 to use the new utility.jar (I thought I shouldn't have to because the ear2 application hadn't been modified - so it should continue to work as normal using the 'old' utility.jar file held within the ear).

      So, now that ear1 uses the new utility.jar and ear2 uses the old utility.jar, when I deploy both ears at once and try using a bean in ear1 it throws a NoSuchMethodError when the bean tries to use one of my new utility.jar's methods. This can only because it is somehow looking at the jar from ear2.

      I can confirm that I have checked to ensure ear1 definitely does contain the new utility.jar and it does. And as I said before, both ears work fine when deployed separately.

      BTW, I am using application.xml to specify the JARs used by each ear. I'm using separate module elements for each JAR. i.e.

      <module>
       <java>lib/utility.jar</java>
      </module>
      <module>
       <java>lib/3rdParty/log4j.jar</java>
      </module>
      ...
      


      If anyone can shed any sort of light on this weird phenomenon, you'd really make my day :D

      Thanks,

      Lindsay

        • 1. Re: Classpath problems - Beans from one ear are using the JA
          frito

          This is because your ears share one loader repository. Therefore only the first resource in this classpath is passed to both applications.
          Read more about ClassLoader, LoaderRepository and their configuration for deployment units:
          http://www.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration

          • 2. Re: Classpath problems - Beans from one ear are using the JA
            lindsay_h

            Thank you Frito!

            That did the trick.

            • 3. Re: Classpath problems - Beans from one ear are using the JA
              lindsay_h

              OK the solution you mentioned worked, but I have another question...

              Is it possible to use the MANIFEST file of the EJB JAR file to specify the classpath to the required utility JARs, but yet retain the isolated classloader behaviour that happens when you use application.xml? When I've done this (using JBOSS 3.2.3; JDK 1.4.1), the files specified in the MANIFEST file's Class-Path entry all seem to get loaded into the container's common classloader - which is not the behaviour I'm looking for.

              I'm fairly content to use the application.xml approach (specifying each utility JAR in there), but it means whenever I add a new utility JAR to my application, I need to add to application.xml AND my Build.properties file (Ant). Using the MANIFEST approach, this can be specified in the build script and keeps things a bit more maintainable.

              So does anyone know if what I'm trying to do is possible perhaps under a newer JBoss?

              Thanks,

              Lindsay