title: javax.naming.NamingException, Tomcat7 and Struts2 can't access to DB resource via JNDI
body: <p>I'm developing new web app with Struts2 framework, eclipse, and I've mapped the db structure with Hibernate. The problem is that when I execute my "list" action the framework returns me this error: </p>
  
  <pre>
  
      Struts Problem Report
  
      Struts has detected an unhandled exception:
  
      Messages:   
      This context must be accessed through a java: URL
      Unable to lookup JNDI name [java:comp/env/jdbc/main]
      File:   org/apache/naming/SelectorContext.java
      Line number:    776
  
  </pre>
  
  <p>The server.xml is:
  <code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Server port="8005" shutdown="SHUTDOWN"&gt;
      &lt;Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/&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;Resource auth="Container" defaultAutoCommit="false" driverClassName="net.sourceforge.jtds.jdbc.Driver" maxActive="200" maxIdle="100" maxWait="20000" name="jdbc/main" password="########" type="javax.sql.DataSource" url="jdbc:jtds:sqlserver://10.4.1.85/SBAGRU_DEV" username="****"/&gt;
  
      &lt;/GlobalNamingResources&gt;
      &lt;Service name="Catalina"&gt;
          &lt;Connector connectionTimeout="2000" executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" redirectPort="8443"/&gt;
  
          &lt;Connector SSLEnabled="true" clientAuth="false" keystoreFile="C:\jpeople.bin" keystorePass="gesbanke" keystoreType="PKCS12" maxThreads="200" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="SSL"/&gt;
  
          &lt;!--&lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/&gt; --&gt;
          &lt;Engine defaultHost="localhost" name="Catalina"&gt;
              &lt;Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false"&gt; 
                  &lt;Context docBase="mag0" path="/mag0" reloadable="true" source="org.eclipse.jst.jee.server:mag0"&gt;
                      &lt;ResourceLink global="jdbc/main" name="jdbc/main" type="javax.sql.DataSource" /&gt;
                  &lt;/Context&gt;
              &lt;/Host&gt;
          &lt;/Engine&gt;
      &lt;/Service&gt;
  &lt;/Server&gt;
  </code></pre>
  
  <p></code></p>
  
  <p>I've also hibernate.cfg.xml</p>
  
  <p><code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Server port="8005" shutdown="SHUTDOWN"&gt;
      &lt;Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/&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;Resource auth="Container" defaultAutoCommit="false" driverClassName="net.sourceforge.jtds.jdbc.Driver" maxActive="200" maxIdle="100" maxWait="20000" name="jdbc/main" password="########" type="javax.sql.DataSource" url="jdbc:jtds:sqlserver://10.4.1.85/SBAGRU_DEV" username="****"/&gt;
  
      &lt;/GlobalNamingResources&gt;
      &lt;Service name="Catalina"&gt;
          &lt;Connector connectionTimeout="2000" executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" redirectPort="8443"/&gt;
  
          &lt;Connector SSLEnabled="true" clientAuth="false" keystoreFile="C:\jpeople.bin" keystorePass="******" keystoreType="PKCS12" maxThreads="200" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="SSL"/&gt;
  
          &lt;!--&lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/&gt; --&gt;
          &lt;Engine defaultHost="localhost" name="Catalina"&gt;
              &lt;Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false"&gt; 
                  &lt;Context docBase="mag0" path="/mag0" reloadable="true" source="org.eclipse.jst.jee.server:mag0"&gt;
                      &lt;ResourceLink global="jdbc/main" name="jdbc/main" type="javax.sql.DataSource" /&gt;
                  &lt;/Context&gt;
              &lt;/Host&gt;
          &lt;/Engine&gt;
      &lt;/Service&gt;
  &lt;/Server&gt;
  </code></pre>
  
  <p></code></p>
  
  <p>Any suggestion where I can look? I'm really going crazy! </p>