1

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!

6
  • How is your web application being deployed? Is it a war file? If so, is the mysql-connector jar in the war? Commented Oct 8, 2014 at 13:02
  • set built path correctly means you have the mysql-connector-java.jar in it? Do you run it in eclipse? Commented Oct 8, 2014 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. Commented Oct 8, 2014 at 13:04
  • 1
    What 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. Commented Oct 8, 2014 at 13:04
  • @jens I have put mysql-connector-java.jar file in a folder called libs and I correctly set build path Commented Oct 8, 2014 at 13:16

1 Answer 1

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)
2
  • putting mysql-connector-java.jarin 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? Commented Oct 8, 2014 at 13:33
  • Those applications may not be web applications on tomcat.. Commented Oct 9, 2014 at 11:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.