Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the classpath for JAR files

I have recently just created Java project using Eclipse that requires 2 JAR files (phiget21.jar and the mysql.jar)

Everything works fine when running the programme in Eclipse, and I have noticed the the jar files are saved in a 'lib' folder.

I soon going to me moving the programme off my computer to be used on other machines, so I decided to create a batch file to compile all of the classes and then run.

However, I am having trouble with the locating of the jar files. In the batch file do I require a command something like: set classpath=.:..;mysql.jar:../phidget21.jar, before the compilation of the Java classes?

I have read that the dots (...) have something to do with directories but not entirely sure how to implement them.

My programme is currently saved in these locations:

Project/src/.java files (I have also put the .jar files in here as well as i thought this may make thing s easier)

Project/lib/ .jar files

Any help would be greatly appreciated!

like image 451
JD87 Avatar asked Mar 22 '12 13:03

JD87


1 Answers

while setting the classpath a single dot (.) means current directory. As you jar files are in current directory, you just need to go to your current directory using cd command in DOS prompt, then use

set classpath = .;filename.jar;another filename.jar

Here . represents current directory and semicolon separates each classpaths.

You can even set classpath of more than one jar files using wild card character * which can be read as all.

like image 132
Chandra Sekhar Avatar answered Sep 28 '22 08:09

Chandra Sekhar