tags:

views:

3926

answers:

3

How do i pass parameters to a jar file at the time of execution?

Thanks,

Krisp

+2  A: 

The JAVA Documentation says:

java [ options ] -jar file.jar [ argument ... ]

and

... Non-option arguments after the class name or JAR file name are passed to the main function...

Maybe you have to put the arguments in single quotes.

Peter
+2  A: 

To pass arguments to the jar, java -jar myjar.jar one two

In the main() method of "Main-Class" [mentioned in the manifest.mft file]of your JAR file. And you can retrieve them like this:

String one = args[0];
String two = args[1];

GreenShadow
A: 

is it possible to do this without the java -jar bit at the start?

I can run jar files that don't have parameters just by typing in the name of the jar file at the command prompt. But it doesn't work when parameters are added.

Bob