Now if you have ever written a main, in your Java program, we write it as :-
public static void main(String args[]) {
Here the args, is an array containing the parameters you provided at the command line.
Consider the following example :-
public class CommandLineArgEx {
public static void main(String[] args) {
for(int i=0;i<args.length;i++) {
System.out.println("Argument Number " + (i+1) + " : " + args[i]);
}
}
}
Following would be the output that you will get :-
stephen@steve:~/Development/java/daniweb> java CommandLineArgEx ABC Bcd Efg
Argument Number 1 : ABC
Argument Number 2 : Bcd
Argument Number 3 : Efg
stephen@steve:~/Development/java/daniweb>
So as you see whatever is passed via the command line, is stored in the args[] String array.
Although I have never tried it with a JAR, I do not see why it should not work.
Last edited by stephen84s; Jan 7th, 2009 at 2:12 pm.