title: Tomcat 5.5 doesn't recognize DataSource at startup (Null component Catalina:type=DataSource)
body: <p>I have set up a Postgres 9.0.1 SQL server and a Tomcat 5.5.28 both at my local PC. Both are running fine. But I have not been able to configure Tomcat to make the DataSource available via JNDI. I think I have followed the JNDI HOW-TO from the Tomcat pages to the letter (as well as having tried some other how-to's from other pages, too). But everytime Tomcat starts he displays the error message:</p>
  
  <pre><code>SEVERE: Null component Catalina:type=DataSource,path=/MyApp,host=localhost,class=javax.sql.DataSource,name="jdbc/postgres"
  </code></pre>
  
  <p>Tomcat does start nonetheless, but my database code won't work, because my InitialContext.lookup ends up with nothing.</p>
  
  <p>The postgres driver "postgresql-8.4-701.jdbc4.jar" is copied into the following folders:</p>
  
  <p>I:\Apache Software Foundation\Tomcat 5.5\common\lib</p>
  
  <p>I:\Apache Software Foundation\Tomcat 5.5\webapps\MyApp\WEB-INF\lib</p>
  
  <p>Here is my MyApp/META-INF/context.xml:</p>
  
  <pre><code>&lt;Context path="/MyApp" docBase="MyApp" crossContext="true" reloadable="true" debug="1"&gt;
      &lt;Resource name="jdbc/postgres" 
          auth="Container"
              type="javax.sql.DataSource" 
              username="postgres" 
              password="xxx" 
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://localhost/MyDatabase"
              maxWait="1000"
              maxActive="20" 
              maxIdle="10"&gt;
      &lt;/Resource&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>Here is an excerpt from my MyApp/WEB-INF/web.xml:</p>
  
  <pre><code>&lt;web-app&gt;
  …
  &lt;resource-ref&gt;
      &lt;description&gt;
          Postgres resource reference to a factory
      &lt;/description&gt;
      &lt;res-ref-name&gt;
          jdbc/postgres
      &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>
  
  <p>My project is deployed as a WAR by Eclipse and Tomcat explodes the WAR at startup as a folder. Now the strange thing: If I doesn't start Tomcat by hand, but by Eclipse, everything works!!! Tomcat doesn't come up with the error message above.
  I have discovered Eclipse uses its own server.xml, context.xml etc. when it starts Tomcat itself, but even after comparing those files with Tomcat's regular config files the only difference I have spotted so far is the following additional line in Eclipse's server.xml before the closing "host" tag:</p>
  
  <pre><code>&lt;Context docBase="MyApp" path="/MyApp" reloadable="true" source="org.eclipse.jst.j2ee.server:MyApp"/&gt;
  </code></pre>
  
  <p>But even when I copy this line into Tomcat's own server.xml (without the "source"-attribute), it doesn't work without Eclipse. So Eclipse must do something "extra" which makes finding the DataSource possible, while the "normal" Tomcat configuration fails. Since I have to deploy the WAR on a different server (without Eclipse) I need help to make this run without Eclipse. I think my code is ok, since it works fine with Eclipse's Tomcat, but my configuration of Tomcat 5.5 must be faulty. Any ideas?</p>