• 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. 《javascript语言精粹》——第4章函数

    函数就是对象 [1].函数字面量即(函数表达式)包括四部分: 第一部分:保留字function: 第二部分:函数名称,可有可无: 第三部分:包围在一对小括号的一组参数,参数用逗号隔开: 第四部分:包围 ...

  2. NSCalendar 日历类

    NSCalendar 日历类 Cocoa中对日期和时间的处理 NSCalendar (一) (2008-11-12 21:54:10) NSCalendar用于处理时间相关问题.比如比较时间前后.计算 ...

  3. springmvc的jdbcTemplate 插入 返回主键

    public int insertCustomer(final Customer customer) {        //TODO.        final String sql = " ...

  4. java.lang.UnsupportedClassVersionError: com/T : Unsupported major.minor version问题解决

    编译的时候jdk版本为1.8 2.运行的时候jdk版本为1.7 解决办法:将编译的jdk版本降为1.7,问题解决

  5. iOS 改变导航栏高度

    需求: appdelegate里 rootviewcontroller 是tabbarcontroller,tabbarcontroller里有4个navigationcontroller,改变每个n ...

  6. ARM交叉编译工具链分类说明

    转载整理自:http://www.veryarm.com/cross-tools 从授权上,ARM交叉编译工具链分为免费授权版和付费授权版. 免费版目前有三大主流工具商提供,第一是GNU(提供源码,自 ...

  7. IOS开发中如何判断程序第一次启动(根据判断结果决定是否显示新手操作引导)

    IOS开发中如何判断程序第一次启动 在软件下载安装完成后,第一次启动往往需要显示一个新手操作引导,来告诉用户怎么操作这个app,这就需要在程序一开始运行就判断程序是否第一次启动,如果是,则显示新手操作 ...

  8. git 关联远程库(https协议)

    1.在oschina上新建库 2.在本地文件夹右键->"git Bash here" 3.设置全局变量: git config --global user.name &quo ...

  9. SQLite用法

    SQLite语法:http://blog.csdn.net/ejzhang/article/details/6224915#08 SQLite查询优化:1.http://www.eoeandroid. ...

  10. 使用spol导出exce

    sqlplus 能生产xls的excel文件 connect / as sysdba; SET NEWPAGE 0 SET SPACE 0 SET LINESIZE 80 SET PAGESIZE 0 ...