Gokul Singh wrote:

> ----- Original Message -----
> From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
>
> > Tomcat 4 follows the new rules in the servlet 2.3 PFD spec, which allows a
> > container to change this so that loading starts with your WEB-INF areas
> first.
> >
> > Consider the following scenario - I put a copy of the Postgres JDBC driver
> (just
> > to show that it's not specific to xml parsers :-) in my shared library
> > directory, because lots of my apps need it.  But, one of my webapps needs
> a
> > different version of the Postgres driver, because it depends on a new
> feature
> > that was implemented in a later version.  So, I put the new driver file in
> the
> > WEB-INF/lib directory of my webapp, and install it in Tomcat.
> >
> > Under Tomcat 3.2, the newer driver is ignored (because it's got the same
> class
> > names).  Under Tomcat 4.0, the newer driver is respected for that webap --
> all
> > others continue to use the shared one.
>
> Craig, I have a small doubt here.
>
> If I place the same jar file containing the class xyz.class in the
> tomcat/lib directory and in WEB-INF/lib directory, then will tomcat load the
> class from the tomcat/lib directory or WEB-INF/lib directory? If it is
> loaded from the WEB-INF/lib directory then this class gets loaded by a
> different classloader(webapp class loader) and is incompatible with the
> classes loaded from tomcat/lib.
>

In Tomcat 3.2, the "xyz" class would be loaded from the tomcat/lib directory, by
the system class loader.  Therefore, it would be shared across all webapps (and,
among other things, static variables would be crossing the boundaries).

In Tomcat 4.0, the "xyz" class would be loaded from the WEB-INF/lib directory,
and would be completely independent of the "xyz" class loaded by some other
webapp.

>
> Should the container not check the META-INF/MANIFEST.MF to find out if the
> versions are same and if the versions are same it loads the class from
> tomcat/lib directory.
>

There is a requirement somewhat like this in the 2.3 spec -- your JAR files can
declare dependencies on external shared libraries, using the "Extensions"
mechanism described in the JDK documentation bundle.  For example, you can
declare "my webapp requires JDBC driver Foo, version 1.3 or later, be made
available to me by the container because it is not in my WEB-INF/lib directory".

>
> Or do the specs mandate that any class in the WEB-INF/lib directory
> overrides class found in the tomcat/lib directory.
> Do the classes in WEB-INF/lib override the classes on the classpath in
> tomcat 4.0?
>

The precise spec wording is in Servlet Spec 2.3 (Proposed Final Draft), section
9.6.2, on page 62:

    The classloader that a container uses to load a servlet
    in a WAR must not allow the WAR to override JDK
    or Java Servlet API classes, and is recommended not to
    allow Servlets in the WAR visibility of the web container's
    implementation classes.

    If a web container has a mechanism for exposing
    container-wide library JARs to application classloaders,
    it is recommended that the application classloader be
    implemented in such a way that classes packaged within
    the WAR are able to override classes residing in
    container-wide library JARs.

Tomcat 4.0 follows these recommendations, although you can turn off the
"override" feature by an appropriate setting in server.xml if you want to.  In
particular, the Tomcat 4.0 mechanism for "exposing container-wide library JARs"
is that it creates a classloader that accesses all JAR files under the
$CATALINA_HOME/lib directory, and makes this classloader the parent of all
webapp classloaders.

The details of Tomcat 4.0's class loader architecture are defined in a document
in the source tree, at "catalina/docs/dev/classloaders.html".

>
> Regds,
> Gokul
>
> >
> > Craig McClanahan
> >
>

Craig



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to