• maven依赖引入
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
  • 示例代码,以下是从命令行读取文件路径的例子
private static void main(String[] args) {

        final Options options = new Options();
final Option option = new Option("f", true, "Configuration file path");
options.addOption(option); final CommandLineParser parser = new PosixParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (final ParseException e) {
throw new Exception("parser command line error",e);
} String configFilePath = null;
if (cmd.hasOption("f")) {
configFilePath = cmd.getOptionValue("f");
}else{
System.err.println("please input the configuration file path by -f option");
System.exit(1);
}
if (StringUtils.isBlank(configFilePath)) {
throw new Exception("Blank file path");
} return configFilePath;
}

JAVA 命令行参数解析,org.apache.commons.cli的使用的更多相关文章

  1. Java命令行参数解析

    参考  http://blog.csdn.net/mldxs/article/details/36204079 http://rensanning.iteye.com/blog/2161201 imp ...

  2. Python 中命令行参数解析工具 docopt 安装和应用

    什么是 docopt? 1.docopt 是一种 Python 编写的命令行执行脚本的交互语言. 它是一种语言! 它是一种语言! 它是一种语言! 2.使用这种语言可以在自己的脚本中,添加一些规则限制. ...

  3. python命令行参数解析模块argparse和docopt

    http://blog.csdn.net/pipisorry/article/details/53046471 还有其他两个模块实现这一功能,getopt(等同于C语言中的getopt())和弃用的o ...

  4. gflags命令行参数解析

    gflags库是google开源的命令行参数解析工具. 安装 官方没有提供二进制库,但是Debian/Ubuntu平台本身提供了二进制库,可以直接git clone https://github.co ...

  5. [Go] 命令行参数解析包(flag 包)使用详解

    Go 的 flag 包可以解析命令行的参数. 一.命令行语法 命令行语法主要有以下几种形式: cmd -flag       // 只支持bool类型 cmd -flag=xxx cmd -flag ...

  6. $命令行参数解析模块argparse的用法

    argparse是python内置的命令行参数解析模块,可以用来为程序配置功能丰富的命令行参数,方便使用,本文总结一下其基本用法. 测试脚本 把以下脚本存在argtest.py文件中: # codin ...

  7. Google开源命令行参数解析库gflags

    Google开源命令行参数解析库gflags http://blog.csdn.net/lming_08/article/details/25072899 CMDLINE的解析 http://blog ...

  8. PHP 命令行参数解析工具类

    <?php/** * 命令行参数解析工具类 * @author guolinchao * @email luoyecb@163.com */class CommandLine{ // store ...

  9. golang-flag - 命令行参数解析

    flag - 命令行参数解析 在写命令行程序(工具.server)时,对命令参数进行解析是常见的需求.各种语言一般都会提供解析命令行参数的方法或库,以方便程序员使用.如果命令行参数纯粹自己写代码解析, ...

随机推荐

  1. 起步X5 的铛铛的安装部署过程

    (2017年1月)主要资料: 1.铛铛的IM Server即时通信服务使用 actor   https://github.com/actorapp/actor-platform ,开发者网站是:htt ...

  2. 最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例

    参考http://blog.csdn.net/defonds/article/details/49496895 本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度. ...

  3. Ubuntu各个版本支持时间

    早期版本:

  4. iOS 参考 网络书籍

    网络图书: Xcode中的Project和Target: http://book.51cto.com/art/201307/402283.htm

  5. 5.IP选路,动态选路

    1.静态IP选路 1.1.一个简单的路由表 选路是IP层最重要的一个功能之一.前面的部分已经简单的讲过路由器是通过何种规则来根据IP数据包的IP地址来选择路由.这里就不重复了.首先来看看一个简单的系统 ...

  6. orientationchange

    <!DOCTYPE html> <html> <head> <title>OrientationChange Event Example</tit ...

  7. Reactive 手机网络状态

    RAC([UIApplication sharedApplication], networkActivityIndicatorVisible)

  8. VMware虚拟机与宿主无法复制的解决办法

    由于工作需要,上网机器使用虚拟机,因此需要经常来回的拷贝文件,而vmware从6.5一直走来到10.0.1,总是有一个问题很让人苦恼---共享粘贴板总是会无故失效.经常实验,发现可以经过以下方法临时解 ...

  9. HDU-1256-画8

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1256 这题做的我好苦,开始题目理解错了,一直都不对,仔细看题,别急,慢慢来,别紧张, 难度到不大,但题 ...

  10. Sql server2014 内存优化表 本地编译存储过程

    参考文献:http://www.infoq.com/cn/news/2013/09/Compiled-Queries http://www.bianceng.cn/database/SQLServer ...