3

I have a Java project, it consists of 3 Java classes, one .properties file (including MySQL username, password etc), and a mysql-connector-java-5.1.41-bin.jar

My question is how I could include the mysql-connector-java-5.1.41-bin.jar when compiling. For this, I do the following right now: Navigate to my Java project folder in CMD -> javac StartApp.java -> java StartApp. It is running well except that it cannot find mysql-connector-java-5.1.41-bin.jar when using methods that requires it.

I am using Windows 7.

What could I do? Everything else is working when running the Jar except that the connection to the MySQL is not working (since it cannot localize the connector Jar). I am getting desperate so any help is much appreciated!

It'sOK
  • 65
  • 1
  • 8
  • I am having the same problem, please answer your own question if you solve it. Or if anybody else knows. – L.S Apr 23 '17 at 18:35
  • Did you ever set the classpath ? Have a look at http://stackoverflow.com/questions/11965818/how-to-run-java-program-in-command-prompt – Marged Apr 23 '17 at 22:46

1 Answers1

0

Just add the cp argument to let java know the class path
lets say you are storing all your jar (mysql-connector-java-5.1.41-bin.jar) under lib folder, use this command:

java -cp "yourMain.jar;lib/*" StartApp
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159