You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Omar VEGA <ov...@cti.com.ar> on 2000/05/20 18:31:00 UTC

Tomcat - AdaptiveClassLoader

hi,

I had  problems loading some classes and what I  figured out  is that in the loadClass function
the next piece of code causes the problem:

           // Attempt to load the class from the system
        try {
            c = loadSystemClass(name, resolve);    <----- could raise a NoClassDefFoundError
            if (c != null) {
                if (resolve) resolveClass(c);
                return c;
            }
        } catch (Exception e) {
            c = null;
        }



when a NoClassDefFoundError raises it is not caught by the try{ ...} catch(Exception e) block so I changed it for the next one.

        // Attempt to load the class from the system
        try {
            c = loadSystemClass(name, resolve);
            if (c != null) {
                if (resolve) resolveClass(c);
                return c;
            }
        }catch(NoClassDefFoundError e) {
            c = null;
        }
        catch(Exception x){
            c = null;
        }

and it works fine for me.

Is this correct ? Or I miss something ??

thanx.


Re: Tomcat - AdaptiveClassLoader

Posted by gu...@edamame.stinky.com.
> when a NoClassDefFoundError raises it is not caught by the try{ ...} catch(Exception e) block so I changed it for the next one.
> 
>         // Attempt to load the class from the system
>         try {
>             c = loadSystemClass(name, resolve);
>             if (c != null) {
>                 if (resolve) resolveClass(c);
>                 return c;
>             }
>         }catch(NoClassDefFoundError e) {
>             c = null;
>         }
>         catch(Exception x){
>             c = null;
>         }


I'm having NoClassDefFoundError problems. A WAR file that works fine
in Windows (JDK 1.2.2) fails in Linux (Blackdown 1.2.2 RC4, with or
without JIT). It can't find a class (com.purpletech.util.Cache) that
exists in a JAR in the WAR (WEB-INF/lib/purple.jar).

I tried your fix (I compiled it in, then updated webserver.jar using
"jar uf ../lib/webserver.jar org/apache/tomcat/loader/AdaptiveClassLoader.class") 
and, maddeningly, it seemed to work for a while, but then went back to
failing!

I added in a debug print statement at the start of loadClass(), and
apparently, the AdaptiveClassLoader (or at least its loadClass()
method) isn't even being called to load the offending class. It is
called several times at startup (for classes like DefaultServlet),
then once to load the servlet, but then during the execution, it is
not called; instead, we just see a NoClassDefFoundError (presumably
thrown by the System Classloader).

Of course, I can work around it by adding the JAR it to the system
classpath, but that's not the point: JARs in WARs should work,
shouldn't they?

 - Alex