6

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!

Hephaestus
  • 4,337
  • 5
  • 35
  • 48
JD87
  • 123
  • 2
  • 3
  • 9
  • Two dots `..` mean the upper directory. I'd recommend to build with an Ant script, it's easy to set the classpath there, here is the tutorial http://ant.apache.org/manual/using.html – John Doe Mar 22 '12 at 14:01

2 Answers2

9

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.

Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
  • 2
    Thank you for the reply, this wasn't the exact the way to do it, I'm not exactly sure why but this is what eventually worked: set classpath=.;..;phidget21.jar;mysql.jar – JD87 Mar 22 '12 at 14:45
1

You need something like

java -classpath lib/foo.jar:. com.company.Program

you can also use wildcards since java 6. see here

so the above becomes

java -classpath lib/*:. com.company.Program
krystan honour
  • 6,523
  • 3
  • 36
  • 63