views:

1566

answers:

6

Is there library support for parsing command line arguments in Java?

Preferably in the APIs that are with the default JRE, and supporting UNIX-like arguments

Something along the lines of PERL's GetOpt?

+1  A: 

Apache Commons Command Line Interface

joel.neely
+3  A: 

I've had good luck with args4j.

Hank Gay
+2  A: 

I havn't been able to find a perfect one yet. I've experimented with two so far:

Options This one worked alright for me, but I found it complicated and not everything worked as I expected. Plus, I felt that the examples provided didn't help me as much as I wanted, in my case at least. Nevertheless, this one is quite powerful.

GNU getOpt This is a java port straight from the GNU. When I used it, it wasn't catching all the arguments that I had wanted. However, it could of been something on my end, so give it a try.

Anton
+1  A: 

AFAIK, the standard APIs don't contain such features, but there are several 3rd party options available. See this page for links and feature summaries:

Open Source Command Line Interpreters in Java

Edit: Here's a related question: Are there good Java libraries that facilitate building command-line applications? (Looking at the title it seems broader than this, but a lot of the discussion focuses on argument parsing.)

Jonik
+1  A: 

We've found JSAP to be useful. However, I don't have any experience with PERL's GetOpt, so I'm not sure if its exactly what you're looking for.

bcash
A: 

Google's java gems is another option.

Google has nothing to do with that library. It's just hosted on Google.
Kevin Bourrillion