I want to pass, both, named and unnamed arguments to the main method.
Currently I am passing arguments as:
java -jar myfile.jar param1 param2
and handling them as:
public static void main(String[] args) throws IOException {
String param1 = args[0];
String param2 = args[1];
}
However, I want to pass the arguments in a more dynamic way - namely, so that:
- I can pass, both, named and unnamed arguments;
- I can fetch/handle these arguments with their names;
- I will not be required to pass them in the same order, every time I execute the main method.
Passing in a way Something like this:
java -jar myJar param3name=param3 param2name=param2 param1name=param1 param5 param6
and handling in a way something like this:
public static void main(String[] args) throws IOException {
//something like
String param3 = getvaluemethod("param3name");
String param1 = getvaluemethod("param1name");
.....
String param5 = args[n]
String param6 = args[n+1]
.....
}
I am fine to work with some external libraries which would make my work easier.
I have already seen this and it is not comprehensive.
Any input on how to accomplish the task?