4

I will have multiple webapps. All webapps being java based and using Spring/hibernate etc. If I put all third party jars in each war file ( corresponding to each webapp ); there would be huge memory footprint !

When third party jars ( like spring/hibernate ) are common across all webapps; what is the best way so as to have minimum memory usage ? One option I could think of is to put these third party jars in Tomcat/lib so that they can be shared across multiple webapps..

Is there any other better way ?

Deepak Singhal
  • 10,568
  • 11
  • 59
  • 98
  • 1
    Duplicate of http://stackoverflow.com/questions/267953/managing-libraries-in-tomcat? Solution and pros / cons already discussed there. – AngerClown Jan 05 '13 at 18:43

2 Answers2

4

It sounds to me like you are confusing memory (RAM) with disk storage.

If you're looking to minimize the use of disk space, then yes, you can put the jar files in a shared location - see the documentation at http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html#Shared_Library_Files

This won't do anything for memory usage - each application is going to load the classes that it needs under its own classloader.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • Surely I am not confused between disk storage and ram storage. I am concerned about RAM storage. Disk storages even on AWS micro instance is 10 GB and very cheap. – Deepak Singhal Jan 05 '13 at 18:54
  • 1
    As I said, sharing the jars on disk will not save you any memory usage - each app is going to load its own copy of the jars. – GreyBeardedGeek Jan 05 '13 at 18:58
  • 1
    From the documnets; it looks like that if we put these jars in CATALINA_HOME/lib ; they will not be loaded multiple times and will act like "Shared library files".. Isnt it ? – Deepak Singhal Jan 05 '13 at 19:03
  • Actually, that's not clear to me from the official documentation. There is a 'common' classloader, but it's not explicitly stated whether shared jar files are loaded only once. I think you'd have to try it to find out. – GreyBeardedGeek Jan 05 '13 at 19:50
  • I agree; its not very evident from official documentation. – Deepak Singhal Jan 05 '13 at 19:51
0

Yes, Tomcat's Common class-loader will load these jars in Tomcat's common lib only once because all webapps share the same common class-loader. But some jars won't work due to various issues. So you have to try.

AnthonyY
  • 711
  • 12
  • 17