File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Proper use of /shared/lib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Proper use of /shared/lib" Watch "Proper use of /shared/lib" New topic

Proper use of /shared/lib

Sam Shab

Joined: Jan 24, 2006
Posts: 2
I a nagging question about how to best make use of Tomcat's shared/lib directory that I can't seem to find a solid answer for:

Is there any chance that putting jars which are used over and over in different contexts and virtual hosts into tomcat/shared/lib will cause interaction problems across contexts? Specifically, I remember reading something a while back about Struts and Jakarta Commons libraries interacting with each other in subtle and unpleasant ways when shared in this way instead of each residing in their respective WEB-INF/lib directory.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

The only thing that comes to mine is static objects that you intended only to exist accross applications could exist accross multiple non-related applications. I don't know about the specific problems that could arise in the libraries you mention, but as a general rule its a bad practice for most application-related jars.

[OCA 8 Book] [Blog]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Any static variables will be shared across all webapps if the class or jar files are loaded from the tomcat/lib directory.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sam Shab

Joined: Jan 24, 2006
Posts: 2
That makes sense. It seems that the "don't put struts jars in a shared lib" advice I remember revolved around that, too. I believe the other possible gotcha is that WEB-INF/lib jars can see those in shared/lib, but not the other way around, which is the only one I could come up with when I posted.

Thanks for the answers -
Vlad Ilyushchenko

Joined: Jan 26, 2006
Posts: 4
/shared/lib should not be used for sharing java libraries. The name is ambiguous, i know, but this dir is to share libraries between applications and *tomcat container*. You dont want to mess with Tomcat core, do you?

To share libraries between applications only you should use /common/lib
I agree. Here's the link:
subject: Proper use of /shared/lib
It's not a secret anymore!