Remapping JNDI resources in a Java Enterprise Application
<p>We have a common web module (foo.war) we'd like to deploy as a WAR in a number of different EARs.  foo.war accesses the database via a JNDI datasource that foo knows by the name <code>jdbc/FOO-DATASOURCE</code></p>

<p>But for each application XXX, this datasource must be remapped to the the datasource associated with the XXX application, that is <code>jdbc/XXX-DATASOURCE</code>.  </p>

<p>foo.war has the following in its web.xml:</p>

<pre><code>&lt;resource-ref&gt;
    &lt;res-ref-name&gt;jdbc/FOO-DATASOURCE&lt;/res-ref-name&gt;
    &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
    &lt;res-auth&gt;Container&lt;/res-auth&gt;
&lt;/resource-ref&gt;
</code></pre>

<p>I had thought that I could use the following entries in <code>glassfish-application.xml</code> in the XXX project to remap this:</p>

<pre><code>&lt;resource-ref&gt;
    &lt;res-ref-name&gt;jdbc/FOO-DATASOURCE&lt;/res-ref-name&gt;
    &lt;jndi-name&gt;jdbc/XXX-DATASOURCE&lt;/jndi-name&gt;
&lt;/resource-ref&gt;
</code></pre>

<p>but when I deploy the XXX app to glassfish, I get the messages:</p>

<pre><code>This app [xxx-ear-0.0.1-SNAPSHOT] has no resource reference by the name of [jdbc/FOO-DATASOURCE]
DPL8007: Unsupported deployment descriptors element jndi-name value jdbc/XXX-DATASOURCE
</code></pre>

<p>Is there some way I can set up a translation at the EAR-level for the resource defined in the web.xml?<br>
Where is glassfish looking for the resource reference?<br>
Is there a better way to accomplish this?</p>