title: javax.naming.NameNotFoundException: Name [jdbc/projectCon] is not bound in this Context. Unable to find [jdbc]
body: <p>I got a webapp deployed on a tomcat 8.0.41. The webapp should connect to a mysql server 5.7.</p>
  
  <p><strong>Worth Mentionig</strong></p>
  
  <p>Both the tomcat- and the mysql-server are running as docker-container. This is why the the msyql-url is: "jdbc:mysql://db:3306/ProjectDB". The jdcb-jar is added to the tomcat via docker-compose. But I think it should not be the source of the error. </p>
  
  <p><strong>ConnectionBuilder.java</strong></p>
  
  <pre><code>package Persistence;
  
  import java.sql.Connection;
  import java.sql.SQLException;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.sql.DataSource;
  
  public class ConnectionBuilder {
  
      public Connection conn;
  
      public ConnectionBuilder()throws NamingException, SQLException {
  
          Context intitialContext = new InitialContext();
          Context environmentContext = new InitialContext();
          environmentContext = (Context) intitialContext.lookup("java:comp/env");
  
          DataSource dataSource = (DataSource) environmentContext.lookup("jdbc/projectCon");
          this.conn = dataSource.getConnection();
      }
  }
  </code></pre>
  
  <p><strong>server.xml</strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;Server port="8005" shutdown="SHUTDOWN"&gt;
      &lt;Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/&gt;
      &lt;Listener className="org.apache.catalina.core.JasperListener" /&gt;
      &lt;Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/&gt;
      &lt;Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/&gt;
      &lt;Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/&gt; 
  
  
    &lt;GlobalNamingResources&gt;
  
          &lt;Recource 
              name="jdbc/projectCon"
              global="jdbc/projectCon"
              type="javax.sql.DataSource"
              auth="Container"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              maxActive="15"
              maxIdle="3"
              maxWait="-1"
              removeAbandonedTimeout="300"
              defaultAutoCommit="true"
              username="admin"
              password="password"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://db:3306/ProjectDB"
          /&gt;
    &lt;/GlobalNamingResources&gt;
  
    &lt;Service name="Catalina"&gt;
      &lt;Connector port="8080" protocol="HTTP/1.1"
                 connectionTimeout="20000"
                 redirectPort="8443" /&gt;
      &lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /&gt;
  
      &lt;Engine name="Catalina" defaultHost="localhost"&gt;
  
        &lt;Realm className="org.apache.catalina.realm.LockOutRealm"&gt;
          &lt;Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 resourceName="UserDatabase"/&gt;
        &lt;/Realm&gt;
  
        &lt;Host name="localhost"  appBase="webapps"
              unpackWARs="true" autoDeploy="true"&gt;
  
          &lt;Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                 prefix="localhost_access_log." suffix=".txt"
                 pattern="%h %l %u %t &amp;quot;%r&amp;quot; %s %b" /&gt;
        &lt;/Host&gt;
      &lt;/Engine&gt;
    &lt;/Service&gt;
  &lt;/Server&gt;
  </code></pre>
  
  <p><strong>context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context path="/Project"&gt;
      &lt;ResourceLink
          description="DB Connection" 
          name="jdbc/projectCon"
          global="jdbc/projectCon"
      type="javax.sql.DataSource"
      /&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" 
           xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;
  
  &lt;recource-ref&gt;
      &lt;res-ref-name&gt;jdbc/projectCon&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;/recource-ref&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
      &lt;param-value&gt;Development&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;session-config&gt;
      &lt;session-timeout&gt;
          30
      &lt;/session-timeout&gt;
  &lt;/session-config&gt;
  
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;login.xhtml&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>StackTrace:</strong></p>
  
  <pre><code>javax.faces.el.EvaluationException: javax.naming.NameNotFoundException: Name [jdbc/projectCon] is not bound in this Context. Unable to find [jdbc].
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
      at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2445)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p><strong>This also happens at deploying:</strong></p>
  
  <p>26-Feb-2017 21:49:15.201 INFO [localhost-startStop-1] com.sun.faces.config.ConfigureListener.contextInitialized Initializing Mojarra 2.2.14 ( 20161114-2152 unable to get svn info) for context '/project'</p>