The online racing simulator
#1 - amp88
Java - running program from bat file and specifying external JAR file
I'm one of those people who gets frustrated with the classpath in Java. I've tried a few things but nothing seems to be working.

I have a program which I need to run from a bat file and it uses an external library which I can't seem to specify in the bat file. The external library is in a jar and isn't in the same directory as the main class for the program I'm trying to run. I'm running the program from a bat file which is located one directory above the directory containing the main file for the program.

Can someone please tell me what arguments I need to specify in my bat file to be able to tell my program where the external library resides in absolute terms, please?

My current bat file to run the program is "java finances/FinancesStart"

Pulling my hair out in anticipation, thanks in advance.
-
(MonkOnHotTinRoof) DELETED by MonkOnHotTinRoof
#2 - Stuff
Quote from amp88 :
My current bat file to run the program is "java finances/FinancesStart"

I think there are a couple things that you need to do differently. Firstm I'll assume that "FinancesStart" is your main class, and isn't in a package (i.e., it doesn't have a "package" directive at the top of the .java file). Second, you don't specify the name of the library you want to include on the classpath, so let's pretend it's called "foo.jar" and it's in a folder called "lib" under your current directory. I'll also assume you're using Windows. If you're using a *nix variant, the only thing that changes is the separator character in the classpath arg, which will change to a colon from a semicolon. Here's the command line:

java -cp "lib/foo.jar;finances" FinancesStart

The "-cp" arg tells the java VM to look in "lib/foo.jar" and the directory "finances" for the classes it wants to use. If FinancesStart is in a package called "finances" (i.e., there is a line that says "package finances;" at the top of FinancesStart.java), then the command line would look like this:

java -cp "lib/foo.jar;." finances.FinancesStart

*Note the "." in the classpath arg
#4 - amp88
Thanks for the quick (and very helpful) reply. FinancesStart is my main class and it is in a package called finance. The second example you've given works perfectly when given the full path of the jar file. It could be a better idea to include the jar file in the directory for this package though, less hassle if I use relative paths I suppose. Anyway, much appreciated.

FGED GREDG RDFGDR GSFDG