37

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?

4 Answers 4

51

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!

Sign up to request clarification or add additional context in comments.

Comments

13

What version of CLI are you using? DefaultParser wasn't added until the 1.3 snapshot.

http://commons.apache.org/proper/commons-cli/apidocs/org/apache/commons/cli/DefaultParser.html

2 Comments

but maven has till 1.2 only. when will maven get 1.3-SNAPSHOT?
Where do you find the 1.3-Snapshot for download?
10

I've encountered the same problem while following same usage guide with commons-cli 1.2 and found the following available parsers:

  • org.apache.commons.cli.BasicParser
  • org.apache.commons.cli.GnuParser
  • org.apache.commons.cli.PosixParser

They all extends the org.apache.commons.cli.Parser and only implement the flatten method. You can check Parser's javadoc (and implementing parsers) for more information.

Comments

4

this DefaultParser class is of Apache CLI 1.3 so for using this you have to update your class path with jar varsion 1.3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.