This is first time am using apache commons-cli.
Requirement :
i want to use CommandLine and Options in commons-cli to pass my runtime parameters to my java class.
Scenario :
main class – com.test.mian.MyClass
i can run my class from command line by
java -cp $classPath com.test.mian.MyClass -one 1 -two 2 -three 3
how can i do the same from a method of another class by passing these arguments using CommandLine and Options of commons-cli.
and also if there is any other way other than
System.setProperty("key","value");
please suggest too.
Here’s a very stripped down version of something I use. It basically sets up a singleton that gets initialized once and then can be used wherever you want within your program. I chose to store the info in HashMap’s and ArrayList’s because they were easier to deal with later.
In your main, you can then call it like so:
And finally, in some other class you can call it like so:
Hope that helps!