Idea運行web項目時,提示java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解決方法
今天用 idea寫了個工程。結果最後報錯,錯誤信息如下:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1493)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.google.model.ConnDB.getConn(ConnDB.java:16)
at com.google.model.GoodsBeanBO.getGoodsBean(GoodsBeanBO.java:23)
at com.google.servlet.showGoodsClServlet.doGet(showGoodsClServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)
java.lang.NullPointerException
at com.google.model.GoodsBeanBO.getGoodsBean(GoodsBeanBO.java:25)
at com.google.servlet.showGoodsClServlet.doGet(showGoodsClServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)
從頭到尾看了好幾遍,沒發現錯誤。郁悶的要死。調試。。。調試。。。調試。。。丫的!
浪費了幾個鐘頭的時間!竟然腦殘的忘記 google 了! 最後 google 一下。結果出現了。
原來是tomcat找不到MYSQL JAR包!
必須把mysql-connector-java-5.1.7-bin.jar導入到tomcat的lib目錄下面! FUCK!
在java項目中,只需要引入mysql-connector-java-5.1.7-bin.jar就可以運行java項目。
在web項目中,當Class.forName("om.mysql.jdbc.Driver");時myeclipse是不會去查找字符串,不會去查找驅動的。所以只需要把mysql-connector-java- 5.1.7-bin.jar拷貝到tomcat下lib目錄就可以了。
特別在此記錄一下!記錄自己的愚蠢!同時多謝 http://blog.csdn.net/huangbiao86/article/details/6428608 這位朋友的帖子!!
Idea運行web項目時,提示java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解決方法