View Single Post
Join Date: Jul 2007
Posts: 1,176
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Interpreting JAR's launched with parameters

 
0
  #4
Jan 7th, 2009
Now if you have ever written a main, in your Java program, we write it as :-
  1. 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 :-
  1. public class CommandLineArgEx {
  2.  
  3. public static void main(String[] args) {
  4. for(int i=0;i<args.length;i++) {
  5. System.out.println("Argument Number " + (i+1) + " : " + args[i]);
  6. }
  7. }
  8.  
  9. }

Following would be the output that you will get :-

  1. stephen@steve:~/Development/java/daniweb> java CommandLineArgEx ABC Bcd Efg
  2. Argument Number 1 : ABC
  3. Argument Number 2 : Bcd
  4. Argument Number 3 : Efg
  5. 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.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote