I have a requirement to run a program where the runtime arguments are passed in the form,
--argumentName=argumentVaue
and I need to get those values in my main function shown below,
public class TestArguments {
public static void main(String[] args) {
System.out.println(System.getProperty("argumentA"));
System.out.println(System.getProperty("argumentB"));
System.out.println(System.getProperty("argumentC"));
System.out.println(System.getProperty("argumentD"));
for(int i=0; i<args.length; i++) {
System.out.println("Argument " + i + " equals " + args[i]);
}
}
}
When I go through the values in args I just get one big string such as --argumentA=foo. I could just do a string.split("=") to separate the name from the value but this doesn't seem like an elegant way to get the argument values by their name. I thought System.getProperty("argumentName") would do the trick but the values are always null. I'm running my program through a jar like so java -cp "myProgram.jar" com.foo.bar.TestArguments --argumentA=a --argumentB=b --argumentC=c--argumentD=d.