title: java web app and Postgres on websphere-liberty
body: <p>I'm deploying a working Tomcat webapp on websphere-liberty on docker. The webapp connects to a postgres data source on docker. In websphere when I try to get connection with </p>
  
  <pre><code>DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/postgres");
  Connection conn = ds.getConnection();
  </code></pre>
  
  <p>my web.xml is setted as:</p>
  
  <pre><code>&lt;resource-ref&gt;
          &lt;description&gt;postgreSQL Connection&lt;/description&gt;
          &lt;res-ref-name&gt;jdbc/postgres&lt;/res-ref-name&gt;
          &lt;res-type&gt;javax.sql.XADataSource&lt;/res-type&gt;
          &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;/resource-ref&gt;
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code>javax.naming.NamingException: CWNEN1001E: The object referenced by the java:comp/env/jdbc/postgres JNDI name could not be instantiated.
  If the reference name maps to a JNDI name in the deployment descriptor bindings for the application
  performing the JNDI lookup, make sure that the JNDI name mapping in the deployment descriptor binding is correct.
  If the JNDI name mapping is correct, make sure the target resource
  can be resolved with the specified name relative to the default initial context.
  [Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The
  server was unable to obtain an object instance for the java:comp/env/jdbc/postgres reference.
  The exception message was: CWNEN1004E: The server was unable to find the jdbc/postgres default binding with the javax.sql.XADataSource type for
  the java:comp/env/jdbc/postgres reference.]
  </code></pre>
  
  <p>I exlude that is a problem with docker network. What I have setted wrong? Is something in my websphere-liberty?</p>
  
  <p>server.xml is</p>
  
  <pre><code>&lt;server description="Default server"&gt;
  
    &lt;!-- Enable features --&gt;
   &lt;featureManager&gt;
    &lt;feature&gt;webProfile-7.0&lt;/feature&gt;
    &lt;feature&gt;adminCenter-1.0&lt;/feature&gt;
    &lt;feature&gt;jdbc-4.0&lt;/feature&gt;
  &lt;/featureManager&gt;  
    &lt;quickStartSecurity userName="admin" userPassword="password"/&gt;
  &lt;!-- Define the host name for use by the collective.
      If the host name needs to be changed, the server should be
      removed from the collective and re-joined. --&gt;
  &lt;!--  &lt;variable name="defaultHostName" value="localhost" /&gt; --&gt;
  
  &lt;!-- Define an Administrator and non-Administrator --&gt;
  &lt;basicRegistry id="basic"&gt;
    &lt;user name="admin" password="admin" /&gt;
    &lt;user name="nonadmin" password="nonadminpwd" /&gt;
  &lt;/basicRegistry&gt;
  
  &lt;!-- Assign 'admin' to Administrator --&gt;
  &lt;administrator-role&gt;
    &lt;user&gt;admin&lt;/user&gt;
  &lt;/administrator-role&gt;
  
  &lt;!--  &lt;keyStore id="defaultKeyStore" password="Liberty" /&gt; --&gt;
  
  &lt;httpEndpoint id="defaultHttpEndpoint"
               host="*"
               httpPort="9080"
               httpsPort="9443" /&gt;
  
  &lt;remoteFileAccess&gt;
    &lt;writeDir&gt;${server.config.dir}&lt;/writeDir&gt;
  &lt;/remoteFileAccess&gt; 
  &lt;library id="postgres-lib"&gt;
    &lt;fileset dir="/arturial/project/" includes="postgresql-9.4.1208.jre6.jar"/&gt;
  &lt;/library&gt;
  &lt;dataSource id="jdbc-Prima_WA_db" jndiName="jdbc/postgres" type="javax.sql.DataSource"&gt;
    &lt;jdbcDriver libraryRef="postgres-lib"/&gt;
    &lt;connectionManager numConnectionsPerThreadLocal="10" id="connectionManager" minPoolSize="1"/&gt;
   &lt;!--   &lt;properties.oracle user="postgres" password="postgres" -
                 url="jdbc:postgres://172.17.0.3:5432/Prima_WA_db"/&gt; --&gt;
   &lt;/dataSource&gt;
  &lt;!--
  &lt;applicationManager updateTrigger="disabled"/&gt;
  &lt;application id="primawebapp" name="primawebapp" location="war/primawebapp" type="war"&gt;
    &lt;classLoader delegation="parentLast" commonLibraryRef="postgres-lib"/&gt;
   &lt;/application&gt;
  --&gt;
  &lt;/server&gt;
  </code></pre>