title: Deploy an EAR multiple times with different data-sources on the same server
body: <p>Let's assume a Java EE 6 application packaged as an EAR (one EJB-JAR, N web modules and some libraries) using JPA for persistence.</p>
  
  <p>The requirement is, that on one machine the applications for multiple customers need to be run. Each customer has it's own database. </p>
  
  <p>The problem is now, where do you configure the data-source for each customer and how do you tell the application (on deployment or whenever) which data-source to use?</p>
  
  <p><strong>First take:</strong> replace the container-specific JNDI name in persistence.xml with something application-specific. On deployment the the application-specific name needs to be bound to a container-specific name.</p>
  
  <p><strong>The Problem:</strong> from what I read it is not possible to do the referencing withing the persistence.xml, unless you disable the enhancing of entities and thereby reducing performance, unless I completely misunderstand stood. (Source: <a href="http://lists.jboss.org/pipermail/wildfly-dev/2014-January/001541.html" rel="nofollow">http://lists.jboss.org/pipermail/wildfly-dev/2014-January/001541.html</a>)</p>
  
  <p>Secondly I found no way to do the resource-ref on an EAR level, I guess one has to do it in the application.xml, that is in my case generated by maven, hence I've to do it in the POM, but have no clue how, the reference of the EJB plugin is not mentioning.</p>
  
  <p>But maybe I'm just on the wrong track. Any help would be appreciated.</p>
  
  <p><strong>Update - 2014-09-12:</strong> Removing auto-generation of the application.xml from POM.xml and adding <code>&lt;resource-ref/&gt;</code> to the application.xml, mapping the local JNDI name of the data-sources to the container-speicific works. (Which makes me immensely happy.)</p>
  
  <pre><code>&lt;resource-ref&gt;
      &lt;res-ref-name&gt;jdbc/customer-alpha&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.XADataSource&lt;/res-type&gt;
      &lt;lookup-name&gt;java:jboss/datasources/customer-alpha&lt;/lookup-name&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>I'm still not sure if that's really the way one would do it. And there are some other question, but they'd be asked separately, e.g. who would add the mapping to application.xml and when, what would the workflow of deploying such an application be.</p>
  
  <p><br/>-<br/>Martin</p>