3 Replies Latest reply on Jan 31, 2003 2:24 PM by Joachim Van der Auwera

    Class not found exception

    Joachim Van der Auwera Expert

      I have a .war file with the libraries included in the WEB-INF/lib directory.
      When try to access my servlet, I get a "java.lang.NoClassDefFoundError: classname" error.
      The class is in the library.

      It seems to work fine in 3.0.2 but fails in 3.0.4 and 3.0.6.

      I tried deploying the war unarchived, but that didn't help (found a reference somewhere that this might help).

      If I put the relevant library file in server/default/lib then it works (though the class doesn't find the resource files it uses).

      Has anybody got any clues how to solve this? Thanks.

      Joachim

        • 1. Re: Class not found exception
          Joachim Van der Auwera Expert

          I am starting to realize some extra details.
          The statement about it working in 3.0.2 might be false, as I tested that with a war I have running in 3.0.2 but without some other beans.

          I have three components deployed, two jars and a war file. The jar files are deplyed before the war file. The war file contains three libraries in WEB-INF/lib, one of these is not loaded. However, one of them (Velocity) is!

          JAR1 contains:
          class1
          class2
          p.class1

          the WAR file contains (in WEB-INF/lib) a library p with classes
          p.class1
          p.class2

          For some reason the classloader cannot find p.class2. It appears that the deployment of the jar file seales the package "p". This does not look like proper behaviour.

          How can this be solved ?

          Joachim

          • 2. Re: Class not found exception
            Joachim Van der Auwera Expert

            After some more checking of the classloader mechanism, I started to see the reason, so I changed direction and created an EAR archive with following structure

            ear
            _lib
            __l.jar
            _j.jar
            _w.war

            in the manifest.mf files for the jar and war file I included "Class-Path: lib/l.jar".

            The good news is that everything is fine for j.jar. The bad news that w.jar has a problem finding l.jar if it is deployed as an unpacked archive and a problem finding the jar file in /WEB-INF/lib inside the war file when deployed as a packed archive.

            Any clues anybody?

            Thanks for the help,
            Joachim

            • 3. Re: Class not found exception
              Joachim Van der Auwera Expert

              Ok, I finally figured out what causes all these problems and have found a solution (in case anybody is interested).

              I solved it by structuring my ear differenty.

              The ear now has the following structure

              ear
              _lib
              __l.jar
              __resources.jar
              _j.jar
              _w.war

              The J.jar and w.war files are quite empty and only include a deployment descriptors and the contents for the site. The resources (which are used by classes in l.jar) are in resources.jar.
              Very important, both archives have a "Class-Path: lib/l.jar lib/resources.jar" line in their manifest file (very important to already reference the resources in j.jar, as the j;jar classes use the classpath when loaded to find resources, and don't know about the extensions given by w.war.

              Hope this helps somebody.
              Joachim