1

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.

4
  • How did you try -cp? Commented Nov 21, 2014 at 22:11
  • Through this: java -cp /usr/share/java/mysql-connector-java-5.1.34 -jar /usr/share/map/program.jar Commented Nov 21, 2014 at 22:12
  • I suggest that you build a jar which contains all the dependencies (also called a fat jar). Using Eclipse: Export -> Java -> Runnable Jar File. Using -cp it should work too, but creating a fat jar is a nice approach - and it's easier. Commented Nov 21, 2014 at 22:14
  • As bmargulies said, either place the jdbc jar in the working dierctory of remove all that class path entry and specify all jar you need using -cp including your application's jar and specify the main class of your application. Commented Nov 21, 2014 at 22:24

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I have the classpath in the manifest now removed, java -cp mysql-connector-java-5.1.34.jar -jar notif.jar , also this doesn't works.
-cp and -jar don't go together. Now you need a colon between the mysql jar pathname and the notif.jar pathname. Unless window, in which case a semi.
So you mean: java -cp mysql-connector-5.1.34.jar : -jar notif.jar .. A colon between mysql jar pathname and the notif.jar pathname?
No spaces around the colon. There is plenty of documentation on all of this.
and no -jar. java -cp mysql-connector-5.1.34.jar:notif.jar NameOfMainClass
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.