Use Java EE deployment descriptors to define context parameters

This rule flags Context <Parameter> elements found in the META-INF/context.xml file.

Apache Tomcat allows Context <Parameter> elements to be defined in these locations:

The migration tool only migrates parameter elements in the META-INF/context.xml file. Parameter information defined in the other locations can be copied to the META-INF/context.xml file in order for it to be processed.

If a WEB-INF/web.xml exists in the web project:

Context <Parameter> elements will be flagged under either of the following conditions:

An automated fix will add a new <context-param> element in the web.xml file which represents the Context <Parameter> element if it does not already exist in the web.xml file. If the entry exists, it will be updated.

If the WEB-INF/web.xml does not exist:

All Context <Parameter> elements will be flagged.

An automated fix will create a WEB-INF/web.xml file that includes the appropriate <context-param> elements if the web project is at Java EE 5 or higher. The automated fix will report an error if the web project is at J2EE 1.4 or lower.

For example, consider a META-INF/context.xml file with the following content:

<Parameter
description="Trigger because it does not exist"
name="newEntry"
override="false"
value="abc123"/>
<Parameter
description="Trigger because of different value"
name="parameter_1"
override="false"
value="new Value"/>
<Parameter
description="Will not trigger because of override set to true"
name="parameter_2"
override="true"
value="123"/>

with the following web.xml file in the application:

<context-param>
<description>Trigger because of different value</description>
<param-name>parameter_1</param-name>
<param-value>oldValue</param-value>
</context-param>

<context-param>
<description>Will not trigger because of override set to true</description>
<param-name>parameter_2</param-name>
<param-value>123456789</param-value>
</context-param>

After the automated fix is applied, the web.xml will be updated to contain:

<context-param>
<description>Trigger because it does not exist</description>
<param-name>newEntry</param-name>
<param-value>abc123</param-value>
</context-param>

<context-param>
<description>Trigger because of different value</description>
<param-name>parameter_1</param-name>
<param-value>new Value</param-value>
</context-param>

<context-param>
<description>Will not trigger because of override set to true</description>
<param-name>parameter_2</param-name>
<param-value>123456789</param-value>
</context-param>

For additional information on the context parameter in Tomcat see: