The answer depends on where you have located the class file(s) used by your webapp.
If you put a given class in the Tomcat Common class loader path of $CATALINA_HOME/lib it will be made available to all webapps. The same goes for its cached form.
If you use the Tomcat web application class loader path of webapps/webapp/WEB-INF/classes and webapps/webapp/WEB-INF/lib the classes and corresponding class caches are isolated between applications.
Tomcat does not conform to the way Java natively processes classes, but uses a custom Java class loader.This is to enforce a number of features relating to:
- class processing within a webapp
- class caching per webapp
- preloading and reloading of classes at webapplication startup/runtime
- security in class loading/referencing
The Tomcat custom class loader uses the Java default Bootstrap, Extension and System class loaders, but substitutes the classpath variable used by the System class loader for its own classpath. This has the effect of:
The original classpath is ignored by Tomcat.
A key detail is that a webapp class loader does not delegate class loading to its parents first, but tries to load each class as it is requested. Each loaded class is subsequently cached by the webapp class loader in question. This classloader/cache level can not be shared between webapps.
Everything class loaded by the Common class loader is made publicly available to all webapps, including the cache. Extensive placement of classes in the Common class loader path is discouraged as it:
- breaks portability
- class version requirements may be different between Tomcat and different webapps.
- maintenance becomes an issue, which class belonged to what?
There is quite a bit of fine print attached to the class loading/caching/reloading process. If that is important my suggestion would be to read the outstanding chapter on class loading in the Professional Apache Tomcat 6.
A compressed version has been written by someone on this page.