I am getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
in my dynamic web application even though I have set build path correctly in Eclipse
for mysql connector
. I am pretty sure that I have set built path correctly. I doubled checked that.
I ran through so many same kind of questions in stackoverflow. All of them suggest to set build path in Eclipse
.
My question is, are there any other ways that can generate java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
error? If so , how to solve that?
Thank you!
Asked
Active
Viewed 1,721 times
1

vigamage
- 1,975
- 7
- 48
- 74
-
How is your web application being deployed? Is it a war file? If so, is the mysql-connector jar in the war? – David Oct 08 '14 at 13:02
-
`set built path correctly` means you have the `mysql-connector-java.jar` in it? Do you run it in eclipse? – Jens Oct 08 '14 at 13:02
-
i guess you deploy on an application server, dont you? If you do, you might have to add the jdbc driver jar to your application server lib folder. – user2504380 Oct 08 '14 at 13:04
-
1What eclipse builds into your war, and what classpath your web application uses, these are different things! First you had to check if your war contains the mysql connector. If yes, you had to check the filesystem in your tomcat server, if there is on its place. – peterh Oct 08 '14 at 13:04
-
@jens I have put `mysql-connector-java.jar` file in a folder called `libs` and I correctly set build path – vigamage Oct 08 '14 at 13:16
-
@user3892439 And you run it in eclipse or on a web-/appserver? – Jens Oct 08 '14 at 13:17
1 Answers
2
Keep your mysql-connector-java.jar
file inside Web-INF
folder -> lib
and add it in classpath and then export your WAR and deploy.
This Documentation - http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
says
Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:
- Bootstrap classes of your JVM
/WEB-INF/classes
of your web application/WEB-INF/lib/*.jar
of your web application<----------
- System class loader classes (described above)
- Common class loader classes (described above)

Community
- 1
- 1

Ninad Pingale
- 6,801
- 5
- 32
- 55
-
putting `mysql-connector-java.jar`in `web-INF` worked ! thanks..But I have developped applications without putting that jar file outside that folder, in a seperate folder inside the project folder. What happened this time? – vigamage Oct 08 '14 at 13:33
-