NadirDev
NadirDev

Reputation: 71

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.

Upvotes: 1

Views: 1386

Answers (1)

bmargulies
bmargulies

Reputation: 100196

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.

Upvotes: 2

Related Questions