classpath, eclipse and java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

烂漫一生 提交于 2020-01-02 07:37:19

问题


I have seen & read over 10 similar questions but am still unable to figure it out.

I am using windows7 / Eclipse Helios Service Release 1 / mysql-connector-java-5.1.13-bin.jar.

Everything worked until yesterday, and noW I get this error. I am not aware of anything I did that could have caused this (but maybe still...).

There are no duplicates of this file on my system (nor any other mysql-connector-*).

I am not sure where eclipse is looking for this file, it is sitting under my projects \WebContent\WEB-INF\lib folder with several other .jarS.

looking at the "project" menu -> properties and then "Java Build Path" on the left I see it as one of the libraries under "Web App Libraries" inside the "Libraries" tab. Do I need to add it to the CLASSPATH system environment variable ? (and if so - what would be . in that context ?)

is there a way for me to see (by way of debug) what is the actual path being searched by the class loader?

-=-=-
More info following comments by @javagirl

Q: where did you get the exception? compilation, building, running as java app, under tomcat/etc running?
A: its a runtime exception I get on the eclipse console running tomcat6.

Q: which build tool are you using, ant?
A: AFAIK none. just press play or debug on eclipse. and connect to tomcat from a browser.

Q: is this jar located in the final built package?
A: I don't know how to answer this, but if you can tell me where to look I will. that said I guess the answer is no because search only finds the single instance of the JAR I mentioned.

Q: if you running it under the servlet container like tomcat you probably need to put it in the tomcat/lib folder
A: I am running under tomcat - but not sure where I should actually find this lib folder.

-=-=-

can someone please guide me step by step with resolving this ?


回答1:


so if you are running it under built-in tomcat: you can go to your workspace folder (eclipse workspace folder), there will be folder .metadata.plugins\org.eclipse.wst.server.core\tmp0 (or tmp1,2 - depends on your environment)/wtpwebapps//WEB-INF/lib - here should be located all the jars of your app. If no - try to put it manually (but it's a worst way)

to add it to tomcat lib folder - try to find it? when you create Server in the eclipse it should ask you about installation folder of your tomcat? or it can suggest download it.. so just download/find it, and put there this jar

ps: I afraid you need to read a lot of stuff, you need to be able run your tomcat from command line for example, to better understand all the process and how all is working there.



来源:https://stackoverflow.com/questions/7965017/classpath-eclipse-and-java-lang-classnotfoundexception-com-mysql-jdbc-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!