When I copy mysql jdbc driver to JDK\'s\\jre\\lib\\ext, it execute perfectly well. Now, I want to use the jdbc by specifying its classpath to environment variable. But, after d
You can include any jar files you need by specifying them in the java command with the -cp
switch (which is identical to -classpath
. For example if the JDBC driver's name is 'myjdbc.jar' then you would execute your program as follows:
java -cp myjdbc.jar your.package.YourClass
If you have more jar files, you can separate them with a semi-colon on Windows or colon on Linux/Unix. Commonly the current directly is also included, and we put all needed jar files in a /lib
folder, so it would look something like this (on Windows):
java -cp .;lib/myjdbc.jar your.package.YourClass
Also, if you have lots of jar files, it would be more convenient to put them all in the /lib
folder and have something like this:
java -cp .;lib/* your.package.YourClass