Use Java EE deployment descriptors and WebSphere bindings to define resource references

This rule flags Context <Resource> elements found in the META-INF/context.xml file that might need migration.

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

Since the migration tool might not have access to the Tomcat configuration directory, the migration tool only migrates the META-INF/context.xml file. Resource information defined in the other locations can be copied to the META-INF/context.xml file in order for it to be processed.

An automated fix will take the information from the Resource elements and creates a resource reference or a resource environment reference as needed and a corresponding JNDI name. Tomcat recommends, but does not require, that the corresponding resource reference for the Resource element be defined in the WEB-INF/web.xml. The automated fix will search the list of resource-ref and resource-env-ref elements to see if the entry matching the name already exists. If not, one is created. If the Resource element has an auth attribute, a resource-ref is created. If the Resource element does not have an auth attribute, a resource-env-ref is created. In both cases, the name value is also used as the JNDI name and is defined in the bindings.

For example, given the following Resource element from the META-INF/context.xml file:
<Resource name="jdbc/exampleDB"
auth="Container"
type="javax.sql.DataSource"
description="Example Database"/>


The automated fix will create this corresponding <resource-ref> element:
<resource-ref>
<description>
Example Database</description>
<res-ref-name>jdbc/exampleDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

By default, resources are shareable in Tomcat. If the scope is not set on the Resource element, it is set to shareable when a new resource reference is created for the automated fix. If a matching resource reference already exists in WEB-INF/web.xml, no changes are made.

If the web project is Java EE 5 or higher and the WEB-INF/web.xml does not exist, the WEB-INF/web.xml is created and the new resource reference elements are added. If the web project is at J2EE 1.4 or lower, the automated fix will report an error.

You will also need to configure the resource in the WebSphere configuration.

For additional information on the context resource definition in Tomcat see: