Hi,
I'll have a stab at this one. Any corrections welcome.
When tomcat starts, the tomcat code itself gets loaded via the default
(root) class loader, which knows about CLASSPATH.
Tomcat then creates a class loader for each webapp, giving the
webapp-specific class loader a search path containing only
the webapp/WEB-INF/classes directory, and all jars in
webapp/WEB-INF/lib.
When a servlet or bean class is loaded by tomcat for a webapp,
it gets loaded by the webapp-specific classloader object. This classloader
will first look in the paths it knows about (webapp/WEB-INF/classes
and webapp/WEB-INF/lib/*.jar) and if not found, then pass the request
off to its parent classloader - which is the root classloader, which
knows about CLASSPATH.
So that covers the search order : webapp-specific classes and
webapp-specific jars (sorry, not sure about the order of these two),
then the CLASSPATH.
And because each webapp has a classloader, any code loaded
from webapp1/WEB-INF/classes or webapp1/WEB-INF/lib/*.jar
is completely invisible to webapp2. Separate copies of the bytecode
are loaded, separate copies of static variables exist, static initializers
get run separately, etc.
I think that classes that aren't found by the webapp-specific classloader
(ie are in CLASSPATH not webapp/WEB-INF/..) get loaded by the root
classloader. Therefore, a single copy is loaded (one copy of static
variables,
etc) which is shared by all webapps. This explains why servlet-reloading
works only for servlets in WEB-INF, and doesn't work if the servlet classes
are in CLASSPATH.
Hope I got this at least *mostly* right :-)
Cheers,
Simon
> -----Original Message-----
> From: Ingo Luetkebohle [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, November 09, 2000 4:05 PM
> To: [EMAIL PROTECTED]
> Subject: class load order and conflicts
>
> Hiya,
>
> sorry, this smells like a FAQ but I couldn't find docs :(
>
> In which order are the various class dirs searched for classes?
> /classes and /lib are automatically in the classpath, but are they
> searched last or first?
> Also, say that another servlet different from mine already uses a
> class x contained in a JAR in its /lib dir. I also want to use that
> class but my /lib dir contains a newer version. What will happen? Does
> it depend on which servlet is loaded earlier or does each servlet get
> the class from its /lib dir?
[Kitching Simon]
Tomcat code runs with the system classloader, and creates a new
classloader for each webapp.
Therefore, any class defined
Class is only visible to class B if they have the same classloaded b
> Regards
>
> --
> Ingo Luetkebohle / [EMAIL PROTECTED] / 95428014
>
> its easy to stop using Perl: I do it after every project