java.lang.ClassNotFoundException : JDBC driver in Ubuntu

标签 java jdbc classpath

当我想运行 .jar 文件时出现错误,该 .jar 文件需要 mysql jdbc 驱动程序,并且我已在 mainfest 文件中添加了路径。但这不起作用。我确信这条路是正确的。

这是我的 list 文件:(MANIFEST.MF)

Manifest-Version: 1.0
Main-Class: com.project.beta.Main
Class-Path: mysql-connector-java-5.1.34.jar

这是错误:

Error - Problem with the MySQL server, error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 

我通过 Eclipse 在我的电脑上构建 jar 文件,并在我的 Ubuntu 服务器上运行该 jar 文件。

PS:我也尝试过使用 -cp,但也不起作用。

最佳答案

因为您的 list 中有 mysql jar,所以如果您在 jar 文件上使用 java -jar 启动,Java 会将其添加到类路径中 - 但该 mysql jar 需要位于 java 的当前工作目录中找到它。它不会进一步搜索。您可以使用 -verbose 选项获取有关 Java 正在执行的操作的更多信息。

当您构建应用程序时,建议您开始使用完整的工具,例如 maven 或 ant。在每种情况下,您都可以添加一些工具来帮助您创建包装器 shell 脚本,以将内容添加到类路径并设置其他选项。

关于java.lang.ClassNotFoundException : JDBC driver in Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27071223/

相关文章:

java - 具有空的 Autowiring 依赖项的 Spring Boot JavaConfig

java - 如何在java jdbc应用程序的属性文件中编写复杂的sql查询

classpath - 错误 listenerStart - JaxWS - JBoss as 7

string - 如何在没有外部依赖的情况下从类路径读取文件?

java - "if else"中的 break 语句 - java

java - 为什么 SimpleDateFormat::format(Long) 适用于 Java?

mysql - Groovy:RedHat:java.sql.SQLException:没有找到适合 jdbc:mysql 的驱动程序:

java - 遍历结果集,我需要在满足条件时更新表

java - 如何将eclipse jdt jar库放入Java Build Path中?

java - 如何使用正则表达式来匹配最后两个字符是前两个字符倒序的任何字符串