This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Embeding application jars and resources in tomcat 6? Classloader question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Embeding application jars and resources in tomcat 6? Classloader question" Watch "Embeding application jars and resources in tomcat 6? Classloader question" New topic
Author

Embeding application jars and resources in tomcat 6? Classloader question

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
I remember in previous versions of tomcat 3,4,5 embeding jars and resources ( properties files ) under tomcat shared directories. This meant that my war file could contain only the things that changed JSPs + java and was much smaller also the applications could share resources.

Looking at the Tomcat 6 documentation this is no longer the case http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html.

There seems only now to be the Common directory where they say you shoudl not add resources and the webapps themselves.

Is this the case? Do jars have to be under the web app now?

Thanks

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

From the link you posted:


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 classses (described above)
* /WEB-INF/classes of your web application
* /WEB-INF/lib/*.jar of your web application
* $CATALINA_HOME/lib
* $CATALINA_HOME/lib/*.jar




Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
It mentions in the docs for that are that "Normally, application classes should NOT be placed here". If you look at the docs for 5.5 it has these classloaders..

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 classses (described above)
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
$CATALINA_HOME/common/classes
$CATALINA_HOME/common/endorsed/*.jar
$CATALINA_HOME/common/i18n/*.jar
$CATALINA_HOME/common/lib/*.jar
$CATALINA_BASE/shared/classes
$CATALINA_BASE/shared/lib/*.jar


http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

It seems strange that they have dropped the shared areas, give no alternative but specifically state that you should not use the common area for application jars

To me it looks like they want you to keep all your jars in the individual web application classloader now.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The shared area still works (look at the text in bold in the above quote).
I use it and it works.

Since 2.2 or 2.3, the servlet spec has been pushing the idea of complete web applications; preferring to have multiple copies of files over sharing them between applications, when possible. Disk space is cheap these days and build tools like ANT and Maven make it just as easy to build complete web applications from common code bases at run time. Tomcat has simplified their classloading but there is nothing keeping you from using shared libraries.

I keep one library (some 3rd party middleware by IBM) in the shared directory because it has some JNI code with static variables.
If I didn't keep it in shared, the first app to use it would lock it, keeping the other apps from being able to use it.
Other than that, I keep all libraries, classes, JPSs, etc inside the web app itself.
Any benefits gained from sharing copies are not worth the hassles of trying to share them.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Embeding application jars and resources in tomcat 6? Classloader question
 
Similar Threads
JNLP Webstart- isolating application area from webserver area
Tomcat 5.5 Class loading issues--and I have done some home work on this one
Type mismatch: cannot convert from AccessType to XmlAccessType
JavaServer Faces 1.2 and Tomcat 5.5
Error starting Tomcat in Ubuntu