compiling java into jar files while referencing jar files in other directories

DoughBoy
DoughBoy used Ask the Experts™
on
Hi,
 I have some nice java files.  I would like to compile them into classes and then package them into JAR files. Now, the trick is, in my java files, I am making referencing to other JAR files that are all over my computer. So, how do I reference those other JARS properly in order to compile successfully. I am using Java 1.3 from a command line in Windows 2000. Then once I compile them successfully, how do I correctly place them into JAR files.
50 points for each of my two questions.

TIA
DoughBoy
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
to compile:
javac -classpath /path/to/jar.jar;/path/to/jar2.jar *.java

If you know where the other jars will be when you run your new jar you can specify them in a "manifest" and include that manifest in the jar.
manifest is a file that contains:
Main-Class: com.company.Main
Class-Path: /path/to/jar.jar /path/to/jar2.jar

package your jar with:
jar cmf manifest.file MyJar.jar *.class

run with:
java -jar MyJar.jar

Alternatively you can set the classpath when you call your jar:
java -cp /path/to/jar.jar;/path/to/jar2.jar -jar MyJar.jar

or set classpath in the environment before you run it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial