DefaultParser in Apache Commons CLI

benroth picture benroth · Mar 31, 2013 · Viewed 20.8k times · Source

I wanted to try out the Apache Commons CLI, and figured a good place to start would be the 'usage' section on its web page.

http://commons.apache.org/proper/commons-cli/usage.html

Now, the example suggest to create a DefaultParser, however the closest sounding I could find is BasicParser. Is this the thing to use, am I missing something?

Answer

user2187128 picture user2187128 · Apr 4, 2013

I used GnuParser() instead of DefaultParser() and it works well.

CommandLineParser parser = new GnuParser();

Update : In version 1.3.1 of CLI, GnuParser() is now deprecated. So I simply added

import org.apache.commons.cli.DefaultParser;

and now I use CommandLineParser parser = new DefaultParser();

And all is fine!