我在项目的pom.xml
中有以下依赖项:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
我没有与mySQL
中定义的pom.xml
相关的任何其他内容。
但是,我收到以下错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.myPRJ.ec.utils.DatabaseUtil.getConnection(DatabaseUtil.java:50)
at com.myPRJ.ec.Login.verify.EmailVerifier.verify(EmailVerifier.java:75)
at com.myPRJ.ec.Login.verify.EmailVerifier.getVerify(EmailVerifier.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:722)
我走过磁盘上mysql-connector-java
下的C:\Program Files (x86)\MySQL\Connector.J 5.1\mysql-connector-java-5.1.40-bin.jar
。我在Eclipse上运行mySQL 5.7.0和JDBC 4.0.0。 MySQL在Eclipse / Database Development上直接运行。
我做错了什么?
// =====================
编辑:
Maven没有更新上述依赖标记的存储库。 .m2\repository
中出现的MySQL连接器是2--版本5.1.30和版本5.1.38我手动从那里删除它们 - 左.m2\repository\mysql
为空。然后在Eclipse上运行Update Maven。此更新后.m2\repository\mysql
仍为空。我应该选择哪种MySQL连接器,请做什么?
// ===============
EDIT-2:
原来我把mysql依赖项放在依赖管理标记下,而不是依赖项。在我修好之后,花时间在腐败的罐子上 - maven不断给出奇怪的错误。已经连续工作了6个多小时,抱歉是误报! thx获得富有洞察力的答案/评论。
现在全部修好了。答案 0 :(得分:2)
Tomcat服务器无法加载com.mysql.jdbc.Driver
类,因此您需要将mysql-connector-java-5.1.40.jar
文件添加到Tomcat服务器的应用程序库文件夹(C:\TOMCAT_HOME\apache-tomcat\webapps\YOUR_PROJECT\WEB-INF\lib
),然后重新启动Tomcat服务器。 / p>
答案 1 :(得分:1)
您应该检查您的.m2库是否在部署程序集中。右键单击文件夹项目&gt;部署程序集,然后检查是否有类似m2 / maven库的内容。如果他们不是,请按“添加..”&gt; Java构建路径条目并将其添加到路径WEB-INF / lib中进行部署。重新启动服务器,这应该工作!
编辑 - &GT;在我的eclipse中,名称是Maven Dependencies,Deploy Path是WEB-INF / lib
答案 2 :(得分:0)
当我的mysql-connector的版本与安装的mysql-server不匹配时,我遇到了这个问题。您可以在终端中键入mysql --version
命令来检查mysql版本。您必须通过mysql-server分发号码选择相应的版本,例如如果mysql版本是:Ver 14.14 Distrib 5.7.17。不要使用mysql-connect-java:6.0.6。