Tomcat common/lib vs shared/lib

What is the difference between Tomcat common/lib and shared/lib? Simply put, common/lib contains jar files to be used by both the web server and all deployed web applications. shared/lib contains jar files that are available to all deployed web applications.

Their scope is confusing. From the names (common and shared) alone, I really can't tell which one is used for which purpose. The fact the two directories are located at the same level ($CATALINA_HOME/common $CATALINA_HOME/shared) makes it more confusing. If shared directory were under $CATALINA/webapp, it would make it obvious that it is to be used by all webapps.


Anonymous said...

Nice explanation :)

Timothy Wonil Lee said...

Nice, thank you!

Unknown said...

i'm unable to find the common or shared directories in my tomcat directory. My version is Tomcat 6

Anonymous said...

Good explanation... but i want to ask you a question... at my job, we have several groups of developers working in diferent web applications... each application have different clients, different functional requirements, different time-to-production dead line, etc.. to satisfy some of the functional requirements we are using third-parties libreries (i.e., iText to produce PDF, UploadBean to upload some files to the server, etc..)... some applications use it, some not... because we are several groups, sometimes the coordination to assure all use the same version of this application it's difficult (some of the applications are developed by external contractors, etc..).. besides, there are others legacy application that use older versions of this same libraries...
the question is.. ¿it's worth the effort to coordinate the groups and test the legacy application with the newest version of the libreries to put this libreries in common/lib or shared/lib? ¿or we can safely put this libraries separates in the WEB-INF/lib of every application? Some people tell that puting the libraries in WEB-INF/lib can cause perfomance problems.. it's that true??

and other issue... according to your explanation and the documentation of tomcat, the best place to put the libraries is shared/lib... buy we are planning to migrate to tomcat 6 sometimes near in the future and that version don't have that directory... why it's that? what is trying to achieve the Jakarta Foundation by making this change in tomcat???
ok.. hope you can understand my question (my english is not very well) and you can answer me... a million thx in advance...

javahowto said...

Thanks for the comments.

It can a HUGE effort to coordinate various projects to use the same versions of libraries. Some projects understandably only work with a specific version of some framework/library. So I would not recommend the same-version approach.

Packaging these jars inside each webapp is a valid solution. It will slow down deployment a bit, maybe a couple of seconds, but not too much. But I don't think it will affect runtime performance. Deployment only happens once in a while, so no big deal. At runtime, the WebAppClassLoader will just pick up these libraries directly from WEB-INF/lib, typically lower in the classpath hierarchy than if you put jars in lib/shared. So theoretically it could be a little faster, but predicting performance is as hard as predicting stock market.

I haven't tried Tomcat 6 yet. These days my focus is on glassfish (glassfish.java.net). BTW, you may want to consider migrating from Tomcat to glassfish.

You are not alone on the issue of library conflicts. This issue is also addressed in JavaEE, where it allows you to install different versions of the same library into your appserver, and configure in your application which version is needed. See JavaEE Platform specification on jcp.org (section EE.8.2Library Support). This is not a well-known feature in JavaEE so your dev team may not feel comfortable with it.

To use this feature you will need a full JavaEE appserver like glassfish. Tomcat is just a web container.

Anonymous said...

thx for you rapid answers... your recomendation will help me a lot...

షణ్ముఖన్ said...

we have some common jars which are used by more than one web application.
we want to move those common jars to common/lib.
after moving those jars i am getting exceptions...

how to solve the problem..

Javin @ eclipse remote debugging said...

Thanks a lot for this useful short tutorial.

How Garbage collection works in Java

Unknown said...

Great and Useful Article.

Online Java Training

Java Online Training India

Java Online Course

Java EE course

Java EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Course in Chennai

Java Online Training India

eMexoT said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

Internet Of Things training in electronic city