Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Embeding application jars and resources in tomcat 6? Classloader question

 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic