在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。
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 如何从终端/命令行调用VS代码编辑器
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder