title: Can not find class org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory in Tomcat7/Ubuntu 12.10? (Possible bug)
body: <p>Tomcat 7 has the jar files commons-dbcp.jar and tomcat-dbcp.jar but in tomcat-dbcp.jar, it is the file org.apache.tomcat.<strong>dbcp</strong>.BasicDataSourceFactory class instead of org.apache.tomcat.<strong>dbcp.dbcp</strong>.BasicDataSourceFactory that is looking for.</p>
  
  <p><strong>root cause</strong></p>
  
  <pre><code>javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]
      org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:121)
      javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
      org.apache.naming.NamingContext.lookup(NamingContext.java:843)
      org.apache.naming.NamingContext.lookup(NamingContext.java:154)
      org.apache.naming.NamingContext.lookup(NamingContext.java:831)
      org.apache.naming.NamingContext.lookup(NamingContext.java:168)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>Servlet code</p>
  
  <pre><code>import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  import javax.annotation.Resource;
  import javax.sql.DataSource;
  
  @WebServlet("/person.do")
  public class PersonServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      @Resource(name = "jdbc/javalabs")
      DataSource ds;
  
      public PersonServlet() {
          super();
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          try {
              Connection con = ds.getConnection();
  
              Statement stmt = con.createStatement();
              String query = "select * from t_person";
              ResultSet rs = stmt.executeQuery(query);
  
              PrintWriter out = response.getWriter();
              response.setContentType("text/html");
              out.print("&lt;center&gt;&lt;h1&gt;Person Details&lt;/h1&gt;&lt;/center&gt;");
              out.print("&lt;html&gt;&lt;body&gt;");
              out.print("&lt;table border=\"1\" cellspacing=10 cellpadding=5&gt;");
              out.print("&lt;tr&gt;&lt;th&gt;ID&lt;/th&gt;");
              out.print("&lt;th&gt;First Name&lt;/th&gt;");
              out.print("&lt;th&gt;Last Name &lt;/th&gt;");
              out.print("&lt;th&gt;Date of birth&lt;/th&gt;&lt;/tr&gt;");
  
              while (rs.next()) {
                  out.print("&lt;tr&gt;");
                  out.print("&lt;td&gt;" + rs.getLong("id") + "&lt;/td&gt;");
                  out.print("&lt;td&gt;" + rs.getString("firstName") + "&lt;/td&gt;");
                  out.print("&lt;td&gt;" + rs.getString("lastName") + "&lt;/td&gt;");
                  out.print("&lt;td&gt;" + rs.getDate("dob") + "&lt;/td&gt;");
                  out.print("&lt;/tr&gt;");
              }
              out.print("&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;");
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      public void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
      }
  }
  </code></pre>
  
  <p>META-INF/context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;!-- The contents of this file will be loaded for each web application --&gt;
    &lt;Context crossContext="true"&gt;
  
      &lt;!-- Default set of monitored resources --&gt;
      &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
  
     &lt;Resource name="jdbc/testDB" auth="Container"
          type="javax.sql.DataSource"
          maxActive="100" maxIdle="30" maxWait="10000"
          username="myuser"
          password="myuser"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/javalabs"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>Element in WEB-INF/web.xml</p>
  
  <pre><code>  &lt;resource-ref&gt;
      &lt;description&gt;DB Connection&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/testDB&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;
  </code></pre>