tags:

views:

208

answers:

7

Hi all,

For Command Line parsing in Java, I typically use Apache Commons CLI. Can anybody recommend any alternative libraries?

Thank you! J.

+3  A: 

Does this answer help? http://stackoverflow.com/questions/367706/is-there-a-good-command-line-argument-parser-for-java

Chris
I appreciate these links to alternative frameworks and I have to admit I didn't notice this very similar question. However, I was hoping to reach somebody who *actually tried* different alternatives and who is able to *recommend* one of those.
Jan
In the respect, this is the kind of article I was looking for: http://furiouspurpose.blogspot.com/2008/07/command-line-parsing-libraries-for-java.html Thank you!
Jan
+1  A: 

I see a few listed here command line interpreters

Pangea
+1  A: 

At java-source.net you can find at least 4 other alternative libraries to Apache Commons CLI.

Adrian A.
A: 

getopt-1.0.11 is a simple easy to use lightweight library I used once for command line arguements parsing

Gopi
+3  A: 

JCommander sounds like a very simple and interesting approach to parsing command line arguments with annotations (from the creator of TestNG):

You annotate fields with descriptions of your options:

import com.beust.jcommander.Parameter;

public class JCommanderTest {
  @Parameter
  public List<String> parameters = Lists.newArrayList();

  @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
  public Integer verbose = 1;

  @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
  public String groups;

  @Parameter(names = "-debug", description = "Debug mode")
  public boolean debug = false;
}

and then you simply ask JCommander to parse:

JCommanderTest jct = new JCommanderTest();
String[] argv = { "-log", "2", "-groups", "unit", "a", "b", "c" };
new JCommander(jct, argv);

Assert.assertEquals(jct.verbose.intValue(), 2);
matt b
This is how Cederic introduced it: http://beust.com/weblog/2010/07/13/announcing-jcommander-1-0/
Jan
A: 

I use and like

http://martiansoftware.com/jsap/

its open source, simple. Its not active, I think the author has other irons in the fire.

fishtoprecords
+1  A: 

I use args4J at https://args4j.dev.java.net/

gliptak