0

I have created a project in eclipse and added jdbc jar library successfully.When I run the program in eclipse I see no error but When I type:

 javac *.java 

in console no problem occur but later when I type

java Runner

I get "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" and more errors related to this."Runner" is the class which has the main method. But in eclipse eveyrthing was working fine.

SANN3
  • 9,459
  • 6
  • 61
  • 97
Emrah
  • 76
  • 7

4 Answers4

1

This means com.mysql.jdbc.Drive is not on your classpath at runtime when you run your program outside of Eclipse. Add it to your classpath.

Try java -classpath or java -cp.

Try also java -help for help and additional details.

See also: http://reins.altervista.org/java/A_Collection_of_JVM_Options_MP.html

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
0

You need the jar file at run time as well.

Use java -cp pathToYourJar Runner

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
0

Because eclipse already has a classpath, when running from command line you need to specify it also.

Eugene
  • 117,005
  • 15
  • 201
  • 306
0

As the others say, you need to pass to javac command the classpath, the way to do it is explained in the following question

Including jars in classpath on commandline (javac or apt)

Community
  • 1
  • 1
iouardi
  • 96
  • 1