在Java中解析命令行参数的好方法是什么?


当前回答

看一看最近的JCommander。

我创造了它。我很高兴收到问题或功能请求。

其他回答

For Spring users, we should mention also https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/env/SimpleCommandLinePropertySource.html and his twin brother https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/env/JOptCommandLinePropertySource.html (JOpt implementation of the same functionality). The advantage in Spring is that you can directly bind the command line arguments to attributes, there is an example here https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/env/CommandLinePropertySource.html

Argparse4j是我发现的最好的。它模仿Python的argparse库,非常方便和强大。

我使用过JOpt,发现它非常方便:http://jopt-simple.sourceforge.net/

首页还提供了一个大约8个备选库的列表,检查它们并选择最适合您的需求。

航空公司@ Github看起来不错。它基于注释,并试图模拟Git命令行结构。

是的。

我想你在寻找这样的东西: http://commons.apache.org/cli

Apache Commons CLI库提供了一个用于处理命令行接口的API。