views:

592

answers:

3

I'd like to deploy the same web application for a number of different customers. Each deployment needs a different value in one of the elements of the web.xml configuration file.

Without building a different .war file for each customer (with the different values set in the web.xml in each .war), is it possible to configure the values for the different customers? For example, can a web.xml file pick up values from a per deployment properties file?

We're using Tomcat as out servlet container.

A: 

The short answer: without changing the war it is not possible.

A more elaborate version: the war can contain some parameters and default values which you can often change using the console of the application server or web server. It depends on what you want to configure, are these standard context/servlet/... parameters?

Bruno Ranschaert
+1  A: 

can you move this element outside the web.xml? If you can perhaps read it from a property file then you can create a different property file for each customer and package the war with the property file for each customer. Then at run time you can read the appropriate property file based on an environment variable.

neesh
+1  A: 

You can specify the changing property outside of the web.xml by using Tomcat's JNDI support.

For example, specify an environment entry within a Context element:

<Context ...>
  ...
  <Environment name="maxExemptions" value="10"
         type="java.lang.Integer" override="false"/>
  ...
</Context>

Then specify a link to this environment variable in your web.xml:

<env-entry>
  <env-entry-name>maxExemptions</param-name>
  <env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>

And then call from your code using (from Professional Apache Tomcat 6):

private final Object lock = new Object();
...
synchronized (lock) {
    Context initCtx = new InitialContext();
    Context envCtx = initCtx.lookup("java:comp/env");
    Integer maxExemptions = (Integer) envCtx.lookup("maxExemptions");
}

Or you can inject your value into your application with Spring using <jndi-lookup />

<bean id="someBean">
    <property name="maxExemptions">
        <jndi-lookup jndi-name="xxx" />
    </property>
</bean>
toolkit