This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Embeding application jars and resources in tomcat 6? Classloader question

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic