mysql - jetty无法加载mysql jdbc驱动

标签 mysql jdbc jetty

我在我的演示应用程序中包含了 mysql jdbc 驱动程序。

/tmp/jettytmp$ find . -name "*.jar"
./jetty-0.0.0.0-8080-auth-0.1.war-_auth-any-7537667183570190622.dir/webapp/WEB-INF/lib/mysql-connector-java-5.1.38.jar

但是,当我尝试登录我的演示应用程序时,java.lang.ClassNotFoundException 抛出:

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at org.eclipse.jetty.security.JDBCLoginService.connectDatabase(JDBCLoginService.java:197)
    at org.eclipse.jetty.security.JDBCLoginService.loadUser(JDBCLoginService.java:238)
    at org.eclipse.jetty.security.MappedLoginService.login(MappedLoginService.java:221)
    at org.eclipse.jetty.security.JDBCLoginService.login(JDBCLoginService.java:222)
    at org.eclipse.jetty.security.authentication.LoginAuthenticator.login(LoginAuthenticator.java:61)
    at org.eclipse.jetty.security.authentication.FormAuthenticator.login(FormAuthenticator.java:194)
    at org.eclipse.jetty.security.authentication.FormAuthenticator.validateRequest(FormAuthenticator.java:270)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:512)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)
2016-03-12 15:41:32.894:WARN:oejs.JDBCLoginService:qtp1980086877-13: UserRealm Admin Login could not load user information from database
java.sql.SQLException: Can't connect to database

从日志中可以看到JDBCLoginService尝试连接数据库,但是没有找到jdbc驱动。但是 jdbc 驱动程序已经包含在演示应用程序中了?如何解决这个问题,任何意见表示赞赏。 我的 jetty 版本是 9.2。我使用以下命令启动演示应用程序: java -jar/*/jetty-distribution-9.2.15.v20160210/start.jar

最佳答案

您正在为 MySQL 驱动程序使用过时的/历史包名。您应该在您的应用程序配置中将其更新com.mysql.jdbc.Driver,如记录here :

With MySQL Connector/J, the name of this class is com.mysql.jdbc.Driver.

完成此操作后,将在运行时发现 mysql-connector-java-5.1.x.jar 是否在类路径中可用。

关于 MySQL JDBC 驱动的配置和使用的详细信息可以在官方 MySQL Connector/J (JDBC) Reference 找到。 .

最新的 MySQL JDBC 连接器可用于 download here .

关于mysql - jetty无法加载mysql jdbc驱动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35959166/

相关文章:

c# - 如何连接到 .NET 框架内的 MySQL 数据库?

java - JDBC 是否有最大 ResultSet 大小?

java - Tomcat 6找不到mysql驱动

java - JDBC 未将 root 用户传递给 DriverManager.getConnection

jetty - 修改 Thymeleaf 模板而无需重新启动服务器

java - 以编程方式将 Jersey REST 服务附加到 Jetty

jetty - ActiveMQ Web 控制台仅在 localhost 上监听

mysql - 存储单向好友关系的紧凑方式?

mysql - 登录到 WAMP mysql 控制台

java - 在 Linux 中进行 Mysql 数据库备份显示 java.io.IOException :