1
votes

Does anyone have a good understanding on the following scenario?

A class can be deployed in tomcat in various locations. It can be simple .class or packed in a jar file. I am listing those options here:

apache-tomcat-6.0.35\shared\classes
apache-tomcat-6.0.35\shared\lib
apache-tomcat-6.0.35\lib
apache-tomcat-6.0.35\webapps\examples\WEB-INF\classes
apache-tomcat-6.0.35\webapps\examples\WEB-INF\lib

If the same class is deployed in all these locations (.class in classes folder hierarchy or packaged in a jar file and copied under *\lib\ hierarchy), what is the rule that tomcat's class loader would use to identify the class it would finally use?

2
From tomcat official documentation site tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order: Bootstrap classes of your JVM System class loader classes (described above) /WEB-INF/classes of your web application /WEB-INF/lib/*.jar of your web application Common class loader classes (described above)Vimal Mathew

2 Answers

3
votes

After doing more research I found the answer:

From tomcat official documentation site
Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:

Bootstrap classes of your JVM
System class loader classes (described above)
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
Common class loader classes (described above)

The locations searched by "Common class loader" are defined by the common.loader property in $CATALINA_BASE/conf/catalina.properties. This is where we enable/define share location; shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar

And the above order explains the logic.

0
votes

This explains it quite well...

http://www.mulesoft.com/tcat/tomcat-classpath#how-it-differs

Notice that

In Tomcat 5.x, a "shared" loader was responsible for loading classes to be shared between applications, located in the directory $CATALINA_HOME/shared/lib. This was abandoned in Tomcat 6, to steer users towards simply replicating shared dependencies in each of the dependent Contexts, for improved portability. This loader is also replaced with the Common loader.

So if you are using Tomcat 6, "shared" is probably not working as you expect.

Ta,

-Bret