I am using Tomcat for hosting my Java Web and Web Service applications for a long time now. Mostly for Spring and Grails applications at the moment.
Lately in one project a discussion came up, about how deal with dependencies/libraries in Tomcat production environments:
In my projects I am deploying big WAR files holding all the required dependencies for the application in WEB-INF/lib folder. The only things I put in the tomcat/lib folder are the JAR files for JDBC connections managed by tomcat.
The customer has a long history with WebSphere and thinks the container should hold most of the the required dependencies. So they want to put JAR files for used frameworks or WebService API’s (like Metro) in the tomcat/lib folder and have skinny WAR files.
The problem with that solution in my opinion is that if you have an application that requires another version of a dependency that is already included in the tomcat/lib folder you can get errors and strange behavior.
Is there some best practice or official document that talks about this issue? What is your opinion about this?
I doubt you will find official documents (from the Tomcat developers/community) to support this theory, although it is very valid. I had to prepare one in my previous job, so that the EAR file of the application could be deployed across multiple J2EE containers.
There is one thing in favour though. You can bring up the IBM Redbook titled “WebSphere Application Server V6.1: Classloader Problem Determination” (quite dated, given that WAS 7 is available) which demonstrates how to created shared libraries in WebSphere. On WebSphere, one can create multiple such libraries for applications that require differing versions. On Tomcat, you are the mercy of an administrator who may not know what a class loader is, given that all shared libraries is dumped into $CATALINA_HOME\lib.
The Redbook also has this bit of advice (replace utility file with utility JAR and you have your answer):