Maheswaran S
Maheswaran S

Reputation: 11

How to do shared library in tomcat version 6.0 in Linux environment?

I have a two application webapp1 and webapp2. Both application use the same library zx.jar. Now i have put the jar in two location /webapp1/ROOT/WEB-INF/lib and /webapp2/ROOT/WEB-INF/lib

But I don't want to load jar twice. I want to use the jar /tomcat/lib ?

How can I implement this in Linux environment?

Upvotes: 0

Views: 1125

Answers (3)

Alpesh Gediya
Alpesh Gediya

Reputation: 3794

Put your library at below location

•Tomcat 6 $CATALINA_HOME/lib   
•Tomcat 5 $CATALINA_HOME/common/lib

More info Apache ClassLoader Howto.

Upvotes: 2

Stephen C
Stephen C

Reputation: 718668

With Tomcat 6, "common" JARs to be shared between multiple servlets should be placed in $CATALINA_BASE/lib or $CATALINA_HOME/lib. It is documented in the Apache 6 - Classloader HOW TO document.

However you need to be careful when you do this because:

  • "common" JARS and other files / directories in the lib directories take precedence over stuff in each webapp,
  • any static variables in "common" classes are actually visible to all webapps, and
  • leakage of types from one webapp to another can cause strange problems; e.g. type casts failing unexpectedly.

Upvotes: 0

Sazzadur Rahaman
Sazzadur Rahaman

Reputation: 7116

Just put your jar in the in the tomcat lib folder ($CATALINA_HOME/lib).

And if you are using maven as build tool, just put <scope>provided</scope> in the dependency of the corresponding jar!

And if you are using Ant to build, just make sure that, you don't copy the jar to the deployed application's lib folder, while building and deploying your application.

Upvotes: 1

Related Questions