You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Glenn Nielsen <gl...@voyager.apg.more.net> on 2001/02/17 14:14:25 UTC

Tomcat 4 class loaders

I was looking at the classloader documentation in cvs at
catalina/docs/dev/classloaders.html and comparing it to
how Tomcat 4 actually sets up the classloaders.  I found
some discrepancies.

According to the docs the System class loader (CLASSPATH)
has bin/bootstrap.jar and $JAVA_HOME/lib/tools.jar.  But in
catalina.sh bin/servlet.jar and bin/naming.jar are also added.

According to the docs the Common class loader includes
bin/servlet.jar and bin/naming.jar, but these are already in
the System classpath.  What need is their to create another
layer of class loading using the Common class loader if it 
is duplicating jar files already in the class path.  Perhaps
the Common class loader could be removed?

In the docs the Server class loader includes all jar files in
/server, but when the class loader is created, it also adds
/classes if it exists.

The Shared class loader includes all jar files in /lib, as documented.

Question?

What if I have some API I want to install that is shared by web
applications, but this API needs to use a properties file?  There
is no place to install it.  Perhaps we could remove /classes from
the Server class loader and add it instead to the Shared class loader.

Regards,

Glenn

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

Re: Tomcat 4 class loaders

Posted by Remy Maucherat <re...@apache.org>.
> I was looking at the classloader documentation in cvs at
> catalina/docs/dev/classloaders.html and comparing it to
> how Tomcat 4 actually sets up the classloaders.  I found
> some discrepancies.
>
> According to the docs the System class loader (CLASSPATH)
> has bin/bootstrap.jar and $JAVA_HOME/lib/tools.jar.  But in
> catalina.sh bin/servlet.jar and bin/naming.jar are also added.
>
> According to the docs the Common class loader includes
> bin/servlet.jar and bin/naming.jar, but these are already in
> the System classpath.  What need is their to create another
> layer of class loading using the Common class loader if it
> is duplicating jar files already in the class path.  Perhaps
> the Common class loader could be removed?

-1. I suggest fixing the catalina.sh script instead. The catalina.bat script
doesn't include any of these in its classpath.

> In the docs the Server class loader includes all jar files in
> /server, but when the class loader is created, it also adds
> /classes if it exists.
>
> The Shared class loader includes all jar files in /lib, as documented.
>
> Question?
>
> What if I have some API I want to install that is shared by web
> applications, but this API needs to use a properties file?

JAR it :) Ok, that's not very convinient, but it works.
Maybe we could add a lib/classes/ path to the shared classloader.

> There
> is no place to install it.  Perhaps we could remove /classes from
> the Server class loader and add it instead to the Shared class loader.

Remy


Re: [PROPOSAL] Tomcat 4 class loaders

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Remy Maucherat wrote:

>
> Note: Craig may veto these changes because we're so late in the dev cycle.
>

Can you guys please hold off for a while before making *any* changes?  I'm right
in the middle of trying to make Jasper work without having an XML parser exposed
to webapps, and it's going to involve yet another change to status quo.  I will
then update the classloaders doc to reflect current reality, and we can decide
what (if anything) needs to change from there.

>
> Remy
>

Craig


>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: [PROPOSAL] Tomcat 4 class loaders

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
Remy Maucherat wrote:
> 
> > Remy Maucherat wrote:
> >
> > Thats right!  Ok, I retract my proposal for changing the class loaders.
> >
> > > What we can do is add a lib/classes/ repository to the shared
> classloader.
> 
> > I still think it would be a good idea to change the directory structure of
> > where the lib/classes are located to make it clearer where to install
> > libraries/resources.
> 
> I agree with most of the following changes, except that I think it would
> create too many places where you can put libraries (and some are not useful
> IMO in the current situation).
> 
> > System class loader uses jars located in
> > $CATALINA_HOME/system/lib
> > $CATALINA_HOME/system/classes
> 
> -0 to -1.
> Why have a system directory ?
> Right now, the system CL only contains bootstrap.jar (and also tools.jar,
> but it's not in one of TC subfolders), so I would just leave it in bin (it's
> simpler, and people will start to get confused in there are too many places
> where you can put your libraries).
> 

I see your point.  bootstrap.jar can be left in /bin

> > Common class loader uses jars/classes/resources located in
> > $CATALINA_HOME/common/lib
> > $CATALINA_HOME/common/classes
> 
> +1.
> 
> > Shared class loader for web applications uses jars/classes/resources
> located in
> > $CATALINA_HOME/lib
> > $CATALINA_HOME/classes
> 
> +1.
> 
> > Catalina private jars/classes/resources located in
> > $CATALINA_HOME/server/lib
> > $CATALINA_HOME/server/classes
> 
> -0.
> I don't see any situation where splitting the server directory would be
> useful.
> 
> > The classes directories would only be added to the list of URL's for
> > a class loader if it exists
> >
> > And remove servlet.jar and naming.jar from the catalina.sh start script.
> 
> +1.
> 
> Note: Craig may veto these changes because we're so late in the dev cycle.
> 
> Remy
> 

This really isn't much of a change.  Just a few changes to build.xml
and startup/Bootstrap.java, plus updating the docs.

Regards,

Glenn

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

Re: [PROPOSAL] Tomcat 4 class loaders

Posted by Remy Maucherat <re...@apache.org>.
> Remy Maucherat wrote:
>
> Thats right!  Ok, I retract my proposal for changing the class loaders.
>
> > What we can do is add a lib/classes/ repository to the shared
classloader.

> I still think it would be a good idea to change the directory structure of
> where the lib/classes are located to make it clearer where to install
> libraries/resources.

I agree with most of the following changes, except that I think it would
create too many places where you can put libraries (and some are not useful
IMO in the current situation).

> System class loader uses jars located in
> $CATALINA_HOME/system/lib
> $CATALINA_HOME/system/classes

-0 to -1.
Why have a system directory ?
Right now, the system CL only contains bootstrap.jar (and also tools.jar,
but it's not in one of TC subfolders), so I would just leave it in bin (it's
simpler, and people will start to get confused in there are too many places
where you can put your libraries).

> Common class loader uses jars/classes/resources located in
> $CATALINA_HOME/common/lib
> $CATALINA_HOME/common/classes

+1.

> Shared class loader for web applications uses jars/classes/resources
located in
> $CATALINA_HOME/lib
> $CATALINA_HOME/classes

+1.

> Catalina private jars/classes/resources located in
> $CATALINA_HOME/server/lib
> $CATALINA_HOME/server/classes

-0.
I don't see any situation where splitting the server directory would be
useful.

> The classes directories would only be added to the list of URL's for
> a class loader if it exists
>
> And remove servlet.jar and naming.jar from the catalina.sh start script.

+1.

Note: Craig may veto these changes because we're so late in the dev cycle.

Remy


Re: [PROPOSAL] Tomcat 4 class loaders

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
Remy Maucherat wrote:
> 
> > The above changes remove one class loading layer from a web app,
> > allows Common classes to use property files and resources, and cleans
> > up the directories where jar files and classes are located.
> 
> The Catalina core would see the shared libraires, which is a very bad idea
> IMO. We'll get into the same kind of class conflicts and sealing violations
> we now face because Jasper uses JAXP 1.1.
> I really can't see any real benefits (but I can see a lot of problems) in
> removing the shared class loader.
> 

Thats right!  Ok, I retract my proposal for changing the class loaders.

> What we can do is add a lib/classes/ repository to the shared classloader.
> 

I still think it would be a good idea to change the directory structure of 
where the lib/classes are located to make it clearer where to install 
libraries/resources.

System class loader uses jars located in
$CATALINA_HOME/system/lib
$CATALINA_HOME/system/classes

Common class loader uses jars/classes/resources located in
$CATALINA_HOME/common/lib
$CATALINA_HOME/common/classes

Shared class loader for web applications uses jars/classes/resources located in
$CATALINA_HOME/lib
$CATALINA_HOME/classes

Catalina private jars/classes/resources located in
$CATALINA_HOME/server/lib
$CATALINA_HOME/server/classes

The classes directories would only be added to the list of URL's for
a class loader if it exists

And remove servlet.jar and naming.jar from the catalina.sh start script.

Regards,

Glenn

----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

Re: [PROPOSAL] Tomcat 4 class loaders

Posted by Remy Maucherat <re...@apache.org>.
> The above changes remove one class loading layer from a web app,
> allows Common classes to use property files and resources, and cleans
> up the directories where jar files and classes are located.

The Catalina core would see the shared libraires, which is a very bad idea
IMO. We'll get into the same kind of class conflicts and sealing violations
we now face because Jasper uses JAXP 1.1.
I really can't see any real benefits (but I can see a lot of problems) in
removing the shared class loader.

What we can do is add a lib/classes/ repository to the shared classloader.

Remy


[PROPOSAL] Tomcat 4 class loaders

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
After thinking about this some more I have a proposal to change the 
Tomcat 4 class loading.

The class loaders that Catalina uses are organized as follows, where
the parent class loader is above the child class loaders:

                        Bootstrap
                            |
                          System
                            |
                          Common
                       /    |    \
               Catalina  Webapp1  Webapp2  ...


Bootstrap - This class loader contains the basic runtime classes 
provided by the Java Virtual Machine, such as the java.* classes.  
Depending on how your particular JVM is organized, this may 
actually be more than one class loader, or may not exist at all.  
It is generally not referenced directly.

System - This class loader is initialized from the contents of the 
CLASSPATH environment variable.  The standard Catalina startup scripts 
assemble the following repositories for the system class path:

   $CATALINA_HOME/system/lib/bootstrap.jar - The Bootstrap class
   that is used to initialize the Catalina server, and the class
   loader implementation classes it depends on.

   $CATALIA_HOME/system/lib/servlet.jar - The Servlet and JSP
   API classes, placed here so that they are shared between Catalina
   and the web applications that run under it.

   $CATALIA_HOME/system/lib/naming.jar</code> - The JNDI implementation
   used by Tomcat 4.

   $JAVA_HOME/lib/tools.jar - Contains the Java compiler used to 
   compile the servlets generated from JSP pages.

Common - This class loader is where common Java API's shared by
web applications and by Catalina are stored.  For example, this is
where a JDBC driver could be installed so that both web applications
and catalina have access to it. Catalina may need to access the JDBC driver 
if you configure a JNDI JDBC DataSource in your server.xml and a web
application may need access if the JNDI JDBC DataSource is configured
in the web apps web.xml file. This class loader is initialized 
to include all JAR files in the $CATALINA_HOME/common/lib directory, and 
$CATALINA_HOME/common/classes.

Catalina - This class loader is initialized to include all JAR files in the
$CATALINA_HOME/server/lib directory, which should contain Catalina itself 
(i.e. all classes whose fully qualified names begin with org.apache.catalina.), 
and any JAR files that it depends on, and $CATALINA_HOME/server/classes.  
Because these classes are loaded from a  separate class loader, which is 
not visible to the Webapp class loader, they are not visible to web applications.

Webapp - A class loader is created for each web application that is 
installed in Catalina, and initialized to include the WEB-INF/classes 
directory (if it exists), plus all JAR files in the WEB-INF/lib 
directory, for this web app.  Because of the parentage hierarchy, 
web applications can indirectly see (and therefore load classes from) 
the Common, System, and Bootstrap class loaders, but not from the
Catalina class loader.


The above changes remove one class loading layer from a web app,
allows Common classes to use property files and resources, and cleans 
up the directories where jar files and classes are located.

Comments?

Regards,

Glenn

Glenn Nielsen wrote:
> 
> I was looking at the classloader documentation in cvs at
> catalina/docs/dev/classloaders.html and comparing it to
> how Tomcat 4 actually sets up the classloaders.  I found
> some discrepancies.
> 
> According to the docs the System class loader (CLASSPATH)
> has bin/bootstrap.jar and $JAVA_HOME/lib/tools.jar.  But in
> catalina.sh bin/servlet.jar and bin/naming.jar are also added.
> 
> According to the docs the Common class loader includes
> bin/servlet.jar and bin/naming.jar, but these are already in
> the System classpath.  What need is their to create another
> layer of class loading using the Common class loader if it
> is duplicating jar files already in the class path.  Perhaps
> the Common class loader could be removed?
> 
> In the docs the Server class loader includes all jar files in
> /server, but when the class loader is created, it also adds
> /classes if it exists.
> 
> The Shared class loader includes all jar files in /lib, as documented.
> 
> Question?
> 
> What if I have some API I want to install that is shared by web
> applications, but this API needs to use a properties file?  There
> is no place to install it.  Perhaps we could remove /classes from
> the Server class loader and add it instead to the Shared class loader.
> 
> Regards,
> 
> Glenn
> 
> ----------------------------------------------------------------------
> Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
> MOREnet System Programming               |  * if iz ina coment.      |
> Missouri Research and Education Network  |  */                       |
> ----------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-dev-help@jakarta.apache.org

-- 
----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------