简体   繁体   中英

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. But it doesn't works. I am sure that the path is right.

Here my manifest file: (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.

PS: I have also tried this with -cp, but also that doesn't works.

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. It won't search further. You can get more information about what Java is doing with -verbose options.

When you build an application, you would be well-advised to start to to use full tooling, such as maven or 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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