简体   繁体   English

java.lang.ClassNotFoundException:Ubuntu中的JDBC驱动程序

[英]java.lang.ClassNotFoundException: JDBC driver in Ubuntu

I get a error when I want to run a .jar file, the .jar file needs the mysql jdbc driver and I have add the path in my mainfest file. 当我想运行.jar文件时,出现错误,.jar文件需要mysql jdbc驱动程序,并且我在mainfest文件中添加了路径。 But it doesn't works. 但这是行不通的。 I am sure that the path is right. 我确信这条路是对的。

Here my manifest file: (MANIFEST.MF) 这是我的清单文件:(MANIFEST.MF)

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

And this is the error: 这是错误:

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

I build the jar file on my pc through Eclipse, and run the jar file on my Ubuntu server. 我通过Eclipse在PC上构建jar文件,然后在Ubuntu服务器上运行jar文件。

PS: I have also tried this with -cp, but also that doesn't works. PS:我也用-cp尝试过,但这也行不通。

Because you have the mysql jar in your manifest, Java will add it to the class path if you launch with java -jar on your jar file -- but that mysql jar will need to be sitting in the current working directory for java to find it. 因为清单文件中包含mysql jar,所以如果在jar文件上使用java -jar启动,Java会将其添加到类路径中-但该mysql jar必须位于当前工作目录中,以便Java能够找到它。 It won't search further. 它不会进一步搜索。 You can get more information about what Java is doing with -verbose options. 您可以通过-verbose选项获取有关Java所做的更多信息。

When you build an application, you would be well-advised to start to to use full tooling, such as maven or ant. 在构建应用程序时,建议您开始使用完整的工具,例如maven或ant。 In each case, there are facilities you can add to help you create a wrapper shell script to add things to the class path and set other options. 在每种情况下,都可以添加一些工具来帮助您创建包装器外壳脚本,以将内容添加到类路径并设置其他选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM