title: ClassNotFoundException oracle.jdbc.driver.OracleDriver only in servlet, using Eclipse
body: <p>The code below fails on the line:</p>
  
  <pre><code>Class.forName("oracle.jdbc.driver.OracleDriver");
  </code></pre>
  
  <p>with the error: </p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver</p>
  </blockquote>
  
  <p>The two <code>println</code>s print:</p>
  
  <pre><code>Wed_Jun_22_11:18:51_PDT_2005
  false
  </code></pre>
  
  <p>This makes me think the class exists and can be found. Also this exact same class works in an a non-servlet application.</p>
  
  <p>I have rebooted everything multiple times and regenerated the application/servlet multiple times. All values have been hard coded to make it simple and short. </p>
  
  <pre><code>private static Connection getDBConnection() throws Exception {
      System.out.println(oracle.jdbc.driver.OracleDriver.BUILD_DATE);
      System.out.println(Class.class.desiredAssertionStatus());
      //load the driver
      Class.forName("oracle.jdbc.driver.OracleDriver");
  
      return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "SYSTEM", "pass");
  }
  </code></pre>
  
  <p>full servlet that fails:</p>
  
  <pre><code>package servletClass_3;
  
  import java.io.IOException;
  import java.sql.Connection;
  import java.sql.DriverManager;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class OneMoreBookStore
   */
  @WebServlet("/OneMoreBookStore")
  public class OneMoreBookStore extends HttpServlet {
  
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      private static Connection getDBConnection() throws Exception {
  
          System.out.println(oracle.jdbc.driver.OracleDriver.BUILD_DATE);
          System.out.println(Class.class.desiredAssertionStatus());
  
          //load the driver
          Class.forName("oracle.jdbc.driver.OracleDriver");
          return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "SYSTEM", "pass");
      }
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          try
          {
              Connection con = getDBConnection();
          }
          catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>This application works:</p>
  
  <pre><code>package servletClass_3;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  
  public class DBConnect {
  
      private static Connection getDBConnection() throws Exception {
          System.out.println(oracle.jdbc.driver.OracleDriver.BUILD_DATE);
          System.out.println(Class.class.desiredAssertionStatus());
  
          //load the driver
          Class.forName("oracle.jdbc.driver.OracleDriver");
          return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "SYSTEM", "pass");
      }
      public static void main(String[] args) {
          try
          {
              Connection con = getDBConnection();
              System.out.println("connection worked");
              con.close();
          }
          catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>I'm using:</p>
  
  <ul>
  <li>Eclipse JavaEE 1.4.2</li>
  <li>Tomcat 7</li>
  <li>jdk1.7</li>
  <li>Oracle 11g R2</li>
  <li>Windows 7 64bit</li>
  </ul>