2

Sometimes we run java programs in command prompt in this manner

java -jar myjarfile.jar -a "testing" -b "testing2"

How do i know which parameter belongs to which.

My code does not work

String context = System.getProperty("-a")
System.out.println(context) //returns null
aceminer
  • 4,089
  • 9
  • 56
  • 104
  • 2
    getProperty("a"); ? – EDToaster Mar 02 '15 at 07:04
  • 2
    Guess why the main method has this signature: `public static void main(String[] args)`. – isnot2bad Mar 02 '15 at 07:04
  • 1
    Although this is not a real duplicate, looking at this SO question might solve your problem: http://stackoverflow.com/questions/716153/java-command-line-arguments – isnot2bad Mar 02 '15 at 07:07
  • Use a command line parsing library; I personally recommend jopt-simple – fge Mar 02 '15 at 07:16
  • 1
    VM arguments can be accessed by using `System.getProperty("name")` , Application argument can be accessed using String `args` array in the main method – Saravana Mar 02 '15 at 08:49

0 Answers0