Java command line arguments in the format -key = value

Is there a reasonable / easy way to use command line arguments in the format -key = value? I just quickly collected the check for args [i] to see if it contains one of my keys, then take the value for that key and set a variable for it, but there should be a better way. I can't seem to find anything good with a search engine, so I have to look for the wrong thing. Any ideas / insights?

Thanks!

+8
java command-line
source share
1 answer

Try the -D option, allows you to set a key = value pair:

execute a command; note that between -Dkey

java -Dday = Friday -Dmonth = Jan MainClass

In ur ​​code:

String day = System.getProperty("day"); String month = System.getProperty("month"); 
+13
source share

All Articles