title: Tomcat 6 / 7 - how to override a properties file within a Web Application?
body: <p>I've inherited responsibility for a Web Application and the way it manages a properties file just seems wrong. The properties file is supplied within the WAR file and resides within the directory: </p>
  
  <pre><code>&lt;tomcat&gt;/webapps/&lt;my web app&gt;/WEB-INF/classes
  </code></pre>
  
  <p>For first-time installers of our Web Application this is fine. The default properties file has a number of default settings and having default values specified this way seems better than hard-coding the values into the Java code.</p>
  
  <p>This file is ONLY read on Tomcat startup but can be updated by the running Web Application at any time.</p>
  
  <p>Whenever when a customer needs to upgrade the software they must perform the following steps</p>
  
  <ol>
  <li>Stop tomcat to stop the Web Application.</li>
  <li>Make a copy of the file: foo.properties</li>
  <li>Remove the existing web application directory</li>
  <li>Deploy the new war file (purely to unpack it)</li>
  <li>Stop tomcat (again!)</li>
  <li>Copy the old foo.properties over the new one (in WEB-INF/classes)</li>
  <li>Restart tomcat.</li>
  </ol>
  
  <p>This just seems long-winded and error prone - we often have users wipe their properties file by accident. Surely the properties file should be externalised in some manner? I like the idea of the WAR file containing the default values, but is there a way of overriding these values if another file called foo.properties is found such as on the classpath? I really want the new deploy to be:</p>
  
  <ol>
  <li>Stop the Web Application</li>
  <li>Deploy the new Web Application</li>
  </ol>
  
  <p>and it would pick up the properties from the externalised location.</p>
  
  <p>Does Tomcat supply any techniques of doing this or should I simply change the Java code to go looking elsewhere for the properties file (e.g. the user's home directory)?</p>
  
  <p>Whilst writing this question I came across references to conf/catalina.properties and how this could be used to specify directories that would be read ahead of WEB-INF/classes. However modifying common.loader and shared.loader seemed to have absolutely no effect! I got this information from: <a href="http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html" rel="nofollow">http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html</a> .</p>
  
  <p>Any advice greatly appreciated.</p>
  
  <p><strong>UPDATE</strong>
  The properties files are being loaded in via Spring. The beans file has the following:</p>
  
  <pre><code>&lt;value&gt;classpath:foo.properties&lt;/value&gt;
  </code></pre>
  
  <p>Now I could go and change the way that the bean that uses this properties file is instantiated and have a different loading mechanism of the properties file. But since Spring is simply looking at the classpath to obtain foo.properties it seems logical to simply put the customers properties file on the classpath.</p>