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!
1 Answer
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)
-
putting
mysql-connector-java.jar
inweb-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– vigamage10/08/2014 13:33:11Commented Oct 8, 2014 at 13:33 -
Those applications may not be web applications on tomcat..Ninad Pingale– Ninad Pingale10/09/2014 11:43:08Commented Oct 9, 2014 at 11:43
set built path correctly
means you have themysql-connector-java.jar
in it? Do you run it in eclipse?mysql-connector-java.jar
file in a folder calledlibs
and I correctly set build path