java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse

It seems the mysql connectivity library is not included in the project. Solve the problem following one of the proposed solutions:


Add the mysql-connector dependency to the pom.xml project file:


Here you are all the versions:


Add the jar library manually to the project.

Right Click the project — > build path — > configure build path

In Libraries Tab press Add External Jar and Select your jar.

You can find zip for mysql-connector here

  • Explanation:

When building the project, java throws you an exception because a file (the com.mysql.jdbc.Driver class) from the mysql connectivity library is not found. The solution is adding the library to the project, and java will find the com.mysql.jdbc.Driver

If you got the error in your IDE(compile-time error), you need to add your mysql-connector jar file to your libs and add this to your referenced library of project too.

If you get this error when you are running it, then probably its because you have not included mysql-connector JAR file to your webservers lib folder.

Add mysql-connector-java-5.1.25-bin.jar to your classpath and also to your webservers lib directory. Tomcat lib path is given as an example Tomcat 6.0lib

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse

Every one has written an answer but I am still surprised that nobody actually answered it by using the best simple way.

The people answer that include the jar file. But, the error will still occur.

The reason for that is, the jar is not deployed when the project is run. So, what we need to do is, tell the IDE to deploy this jar also.

The people here has answered so many times that put that jar file in the lib folder of WEB-INF. That seems okay, but why do it manually. There is simple way. Check the below steps:

Step 1: If you havent referenced the jar file into the project then, reference it like this.

Right click on the project and go to the project properties.
Then, go to the java build path, then add external jar file via that.

But this will still not solve the problem because adding the external jar via build path only helps in compiling the classes, and the jar will not be deployed when you run the project. For that follow this step

Right click on the project and go to the project properties.
Then, go to the Deployment Assembly then press Add , then go to the java build path entries and add your libraries whether it is jstl, mysql or any other jar file. add them to deployment.
Below are the two pictures which display it.



Leave a Reply

Your email address will not be published.