MychaL
MychaL

Reputation: 999

Tomcat: how is working the shared lib directory?

I made search on subject, but didn't find anything easy to understand... We have a tomcat (v5.5). There is many webapp deployed on it. Each webapp has all librairies in the WEB-INF/lib directory. So there is a lot of duplication.

A classic library (XXX_API) was created in order to organize some common methods. So this librairy is added in each webapp to compile but not deployed with them. This librairy is deployed in shared directory of Tomcat.

We tried to integrate some DAO using JdbcTemplate of Spring 3.1.1 in the common librairy. So we had to deploy Spring librairies in shared directory in order to deploy our XXX_API.

Now, we can't launch all applications. Some of them crashed with these exception : java.lang.IllegalArgumentException. Class org.springframework.jdbc.config.JdbcNamespaceHandler does not implement the NamespaceHandler interface. For information, they are developped with Spring 2.0.6 :(

The problem seems to be localized in the applicationContext.xml.

So, here my questions :

Thank you.

Upvotes: 0

Views: 2868

Answers (4)

MychaL
MychaL

Reputation: 999

So, i have deleted all spring jars in each web application. I imported the spring lib (3.1.1) present in shared directory. And i unchecked them (under netbeans) to not have them in the build.

I even changed the declaration in web.xml, applicationContext.xml and Spring Servlet in order to be standardized with servlet v2.5.

All seems to be fine now...

Upvotes: 0

Matt
Matt

Reputation: 11805

The main use that i've seen for the shared lib folder is for things like jdbc drivers, jta transaction managers and other infrastructure like things that:

  1. The container needs to have available (in the case of jdbc and jta, to create jndi datasources and the jta user transaction)
  2. Are environment specific, like the jdbc driver, when you are going to use the OCI version of the oracle driver. In this case, you have to match the ojdbc.jar file with the version of the native oracle client library installed on that machine. Another example would be jms connectors.
  3. Anything that uses native libraries, as loading that jar multiple times would cause issues when it tried to load the native library a second time.

I wouldn't go putting actual app libraries like spring in the shared lib folder.

Upvotes: 1

irreputable
irreputable

Reputation: 45433

Probably because one class is loaded by app classloader, another by shared classloader.

Save yourself the trouble, don't use shared directory. What for? To save some disk space?

Upvotes: 0

chad
chad

Reputation: 7519

What you are really asking is how the classloaders load, in what sequence, etc. This page explains all of the classloaders that are involved in a webapp's execution inside of the tomcat container quite well. It tells where they look for classes, in what sequence, and which classes can be seen by each webapp as well as the container itself. Note, changes to this are significant across tomcat versions.

http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

Upvotes: 2

Related Questions