I'm getting this error while running tomcat 'java.lang.ClassNotFoundException: com.mysql.jdbc.Driver'. I'm using a combination of Eclipse (Indigo, J2EE version) / Maven (m2e-wtp) / Tomcat 7.0. I've included this dependency in my pom file for my web application (build from scratch).
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
I do not get any compilation errors in the 'Problems' view but when I run the Tomcat server from the 'Servers' view, I get these errors. It clearly indicates that Tomcat is unable to find the Class and it is classpath configuration error and I was hoping that maven would take care of this.
I looked at other issues related to 'java.lang.ClassNotFoundException: com.mysql.jdbc.Driver' but weren't of much help.
I would greatly appreciate any help.
/** This is how I load the Driver */
static {
DriverAdapterCPDS cpds_Customer = new DriverAdapterCPDS();
try { cpds_Customer.setDriver(productConfig.getProperty("dbcp.connection.customer.driver_class"));
} catch (ClassNotFoundException e) {
// log.error("setDriver Exception " + e);
e.printStackTrace();
}
}
Tomcat 7 requires that JDBC driver JARs must go in its /lib directory:
http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
Search for the word "forget".
Make sure the driver actually gets copied to your webapp WEB-INF/lib directory and to wtp deploy dir (something like /.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ in your workspace).
I find maven-wtp integration a bit worse than perfect as i stumble upon this problem very often.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With