Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where/how to setup configuration resources for Tomcat .war files

I have a source tree for a .war file that I need to modify so that I can add some application-specific configuration info (in this case a jdbc connection string, but I may have other properties-like resources). What are the best practices for where to put configuration info and how to access this from within the Servlet?

I'm guessing this Tomcat configuration reference has something to do with it, but my eyes glaze over when I try to read it.

like image 778
Jason S Avatar asked Oct 05 '09 19:10

Jason S


People also ask

Which folder under the Tomcat server installation should you deploy your .WAR file to?

Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat's webapps directory. Copy and paste WAR files into Tomcat's webapps directory to deploy them. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it.

Where is Apache Tomcat configuration file?

The main Apache Tomcat configuration file is at /opt/bitnami/tomcat/conf/server. xml. Once Apache Tomcat starts, it will create several log files in the /opt/bitnami/tomcat/logs directory. The main log file is the catalina.

What is the main configuration file of Tomcat?

The purpose of the server. xml is to define the configuration of an instance of the Tomcat 3.3 web server. The parent configuration elements in the server. xml file represent that instance.

How do I open Tomcat configuration?

Open the Start Menu and choose "Run". Enter "MSCONFIG" and hit Enter to open the System Configuration utility.


1 Answers

For web app configuration you can place the config on the classpath somewhere. Then you can get to it from your application with getResourceAsStream or if you prefer Spring:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <value>classpath:my-config.properties</value>
    </list>
  </property>
</bean>

There are a number of places you can put the properties on the classpath in Tomcat. in order it looks at:

/WEB-INF/classes of your web application 
/WEB-INF/lib/*. jar of your web application 
$CATALINA_HOME/common/classes 
$CATALINA_HOME/common/endorsed/*.jar 
$CATALINA_HOME/common/i18n/*.jar 
$CATALINA_HOME/common/lib / *. jar 
$CATALINA_BASE/shared/classes 
$CATALINA_BASE/shared/lib/*.jar  

For example, if you put my-config.properties both in a .jar file and in WEB-INF/classes the one in WEB-INF/classes will be used. You could use this mechanism to default to test config and override prod config on prod servers.

like image 128
leonm Avatar answered Nov 10 '22 11:11

leonm