title: javax.naming.NameNotFoundException: Name is not bound in this Context. Unable to find
body: <p>I'm trying to find out why my web application throws a </p>
  
  <pre><code>javax.naming.NameNotFoundException: Name [flexeraDS] is not bound in this Context. Unable to find [flexeraDS].
  </code></pre>
  
  <p>when a sister one from which I'm copying the configuration quietly runs.</p>
  
  <p>I have:</p>
  
  <ol>
  <li>create from netbeans a new persistence by right clicking and selecting "new persistence", I don't care about the actual values I give but I just need for the persistence.xml file to be created in the right directory.</li>
  <li>edited my context.xml as below matching the one from working sister project</li>
  <li>edited my web.xml to contain a resource DataSource as shown below</li>
  <li>edited my persistence.xml as below again matching the same values which on the sister project work.</li>
  <li>added all libraries present in the other project inside the lib folder of mine and adding them also from NetBeans to be correctly put inside war.</li>
  </ol>
  
  <h1>context.xml</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context antiJARLocking="true" path="/PetLogin"&gt;
    &lt;ResourceLink global="ds/flexeraDS" name="ds/flexeraDS" type="javax.sql.DataSource"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <h1>web.xml</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app ....&gt;
  &lt;resource-ref&gt;
          &lt;description&gt;DB Connection&lt;/description&gt;
          &lt;res-ref-name&gt;ds/flexeraDS&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;
  &lt;/web-app&gt;
  </code></pre>
  
  <h1>persistence.xml</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="1.0"
               xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd "&gt;
      &lt;persistence-unit name="flexerajpa"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;non-jta-data-source&gt;java:/comp/env/ds/flexeraDS&lt;/non-jta-data-source&gt;
          &lt;properties&gt;
  
              &lt;property name="eclipselink.ddl-generation" value="create-tables" /&gt;
              &lt;property name="eclipselink.ddl-generation.output-mode"
                        value="database" /&gt;
              &lt;property name="eclipselink.weaving" value="static" /&gt;
              &lt;property name="eclipselink.logging.level" value="WARNING" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Now my syster project some-how manages to create its database folder inside apache-tomcat-7.0.40/bin/exampleDB on startup while mine doesn't create it and throws an error as above.</p>
  
  <p>The code where the error is thrown is the first time I connect to the database:</p>
  
  <pre><code>EntityManager entityManager = PersistenceProvider.createEntityManager();
  </code></pre>
  
  <p>where the PersistenceProvider class is:</p>
  
  <pre><code>public final class PersistenceProvider
  {
  
      private static Map&lt;String, Object&gt; lOptions = new HashMap&lt;String, Object&gt;();
  
      static
      {
          lOptions.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, "false");
      }
      private static EntityManagerFactory factory = Persistence
              .createEntityManagerFactory("flexerajpa", lOptions);
  
      private PersistenceProvider()
      {
      }
  
      /**
       * @return
       */
      public static EntityManager createEntityManager()
      {
          return factory.createEntityManager();
      }
  
      /**
       * @return
       */
      public static Metamodel getMetamodel()
      {
          return factory.getMetamodel();
      }
  }
  </code></pre>
  
  <p>I'm out of possible reasons for this.. if anyone has any suggestion.
  Thank you</p>