Search code examples
javatomcatweb-applicationsclassloadertapestry

is it wrong to deploy tapestry jars into tomcat lib directory?


I'm running a tomcat 8 server where I'm deploying several tapestry webapps. When I build the war files with maven, all dependencies (including the tapestry framework jars) are packaged into WEB-INF/lib. So I have the tapestry jars in every single war. As far as I know, tomcat uses a different classloader for every war file so maybe I'm using more memory resources than needed, and that is my concern.

What I've done is to deploy the tapestry jars into ${catalina.base}/lib/tapestry and to update catalina.properties accordingly so that tomcat load the jars inside this directory. Also, I changed the maven dependencies of my projects so that tapestry libraries are not packaged into WEB-INF/lib. It seems to work. But I wonder if there is something wrong with this way of working that may bring problems in the future. Nobody seems to be doing it that way: I couldn't find any information in the tapestry website about whether this is a good or bad policy and why. Does anybody know it?


Solution

  • You'll be better off in the long run to have self-contained war files that each contain as many of their required dependencies as possible rather than relying on "provided" dependencies or other classpath dependencies. There are some cases (but not many) where you need to put the jars outside the war file so the server can access them on startup, but this doesn't sound like one of those cases.

    Putting the Tapestry jars in a shared location would be a completely negligible optimization. Furthermore, it may cause problems later if one of your apps needed a different version of Tapestry.

    Another potential problem is if you switched to a different application server than Tomcat (or even a different version of Tomcat). Different app servers handle class loading in different ways and that's the last type of issue you'll want to contend with.