title: How to get resource from the context.xml file in tomcat webapp?
body: <p>This is my <strong>context.xml</strong> file:</p>
  
  <pre><code>...
  &lt;Resource auth="Container"
            driverClass="net.sourceforge.jtds.jdbc.Driver"
            type="com.jolbox.bonecp.BoneCPDataSource"
            idleMaxAge="240"
            idleConnectionTestPeriod="60"
            partitionCount="3"
            acquireIncrement="1"
            maxConnectionsPerPartition="10"
            minConnectionsPerPartition="3"
            statementsCacheSize="50"
            releaseHelperThreads="4"
  
            name="jdbc/MyDatasource"
            username="my_username"
            password="my_password"
            factory="org.apache.naming.factory.BeanFactory"
            jdbcUrl="jdbc:jtds:sqlserver://localhost:12345/my_database"
  /&gt;
  ...
  </code></pre>
  
  <p>I already tried using <a href="http://docs.oracle.com/javaee/5/api/javax/servlet/ServletContext.html#getResource%28java.lang.String%29" rel="nofollow noreferrer">ServletContext.getResource(java.lang.String)</a> with the name of the resource ("jdbc/MyDatasource"), but Tomcat complains that the name doesn't begin with a '/'. I also tried with "/jdbc/MyDatasource", but this time it returns null.</p>
  
  <p>I mainly need the <strong>jdbcUrl</strong> to perform <strong>a connection check</strong> with the database server (see if the server is online and operational).</p>