I'm new with JCommander
and I'm trying to use it in my JAVA Command Line Application.
Fisrt thing I did is I've created my CommandLineArguments
class.
Now, I'm trying to print options given with arguments in command line. But I think I'm missing something.
Here is my main class :
public static void main(String[] args) {
String[] argv={"-h","host"};
CommandLineArguments arguments=new CommandLineArguments();
JCommander commands= new JCommander(arguments);
try {
commands.parse(argv);
System.out.println(commands.getParsedCommand());
} catch (Exception e) {
System.out.println(e.getMessage());
commands.usage();
}
}
Once I run this class, I got : null
as output. Seems like getParsedCommand()
is not used as it should.
Can someone tell me how to use JCOmmmander
methods correctly so I can see options given with arguments?
What I'm trying to do here is, once the user runs java -jar myApp.jar -port portNumber -h hostname -d database -c collection
I wanna be able to get portNumber hostname database and collection value so I can establish a connexion and send queries.
Hope I was clear enough.
Ismail