Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a java program in that I am using mysql database connectivity code. I have added mysql-connector-java-3.0.10-stable-bin.jar and mysql-connector-java-5.0.4-bin.jar files in my resource folder in eclipse. When I run the program in Eclipse it runs fine. Then I have created a .jar file of my project included all jar files in that jar file. But when I run my jar file with java -jar myJar.jar command on DOS prompt it gives the error - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I tried with setting CLASSPATH of mysql-connector*.jar but still getting the same error. Please help me to resolve this problem?

Thanks in Advance ....

share|improve this question
    
What does this command do? java -cp mysql-connector-java-5.0.4-bin.jar -jar myJar.jar –  opyate Jun 18 '12 at 9:56
    
@opyate: nothing useful: If you use -jar then all other classpath sources (CLASSPATH variable and -cp switch) will be ignored. –  Joachim Sauer Jun 18 '12 at 10:12
    
Thanks opyate for reply, I tried with this command but getting same error –  Deepu Jun 18 '12 at 10:13

2 Answers 2

You need to edit Manifest.txt file to set the classpath for jar

Also See

share|improve this answer
    
Manifest.mf i guess. –  JHS Jun 18 '12 at 10:00
    
Thanks Jigar Joshi for reply, I tried with setting Class-path in Manifest.txt, but still I am getting the error –  Deepu Jun 18 '12 at 10:18
    
Please describe, what have you set and what is the error message –  Jigar Joshi Jun 18 '12 at 10:19
up vote 0 down vote accepted

To resolve the problem you can create "Runnable Jar file" instead of "Simple Jar file" in Eclipse.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.