Apache-common包之common-cli笔记

apache commons包下载 (如commons-logging包) commons的很多包都可以到apache官方网去下:http://commons.apache.org/,它包括如下的包:Components AttributesRuntime API to metadata attributes such as doclet tags.BeanUtilsEasy-to-use wrappers around 阅读详情

  一. common-cli是命令行工具包:包括三个阶段:

1. 定义命令行选项

2. 解析命令行选项

3.解释命令行选项

二. 定义阶段:

Options类是Option类的集合

解析阶段:

CommandLineParser类为命令行解析类,解析返回CommandLine类

解释阶段:

查询CommandLine根据不同组合进行不同分支处理

三. 例子:

// create the command line parser
CommandLineParser parser = new PosixParser();

// create the Options
Options options = new Options();
options.addOption( "a", "all", false, "do not hide entries starting with ." );
options.addOption( "A", "almost-all", false, "do not list implied . and .." );
options.addOption( "b", "escape", false, "print octal escapes for nongraphic "
                                         + "characters" );
options.addOption( OptionBuilder.withLongOpt( "block-size" )
                                .withDescription( "use SIZE-byte blocks" )
                                .withValueSeparator( '=' )
                                .hasArg()
                                .create() );
options.addOption( "B", "ignore-backups", false, "do not list implied entried "
                                                 + "ending with ~");
options.addOption( "c", false, "with -lt: sort by, and show, ctime (time of last " 
                               + "modification of file status information) with "
                               + "-l:show ctime and sort by name otherwise: sort "
                               + "by ctime" );
options.addOption( "C", false, "list entries by columns" );

String[] args = new String[]{ "--block-size=10" };

try {
    // parse the command line arguments
    CommandLine line = parser.parse( options, args );

    // validate that block-size has been set
    if( line.hasOption( "block-size" ) ) {
        // print the value of block-size
        System.out.println( line.getOptionValue( "block-size" ) );
    }
}
catch( ParseException exp ) {
    System.out.println( "Unexpected exception:" + exp.getMessage() );
}

四. 自动生成帮助声明:

// automatically generate the help statement
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "ant", options );

打印出来信息:

usage: ant
-D <property=value>     use value for given property
-buildfile <file>       use given buildfile
-debug                  print debugging information
-emacs                  produce logging information without adornments
-file <file>            search for buildfile towards the root of the
                        filesystem and use it
-help                   print this message
-listener <classname>   add an instance of class as a project listener
-logger <classname>     the class which it to perform logging
-projecthelp            print project help information
-quiet                  be extra quiet
-verbose                be extra verbose
-version                print the version information and exit

        
Apache Common-cli简单使用 概述 Apache Commons CLI是开源的命令行解析工具,它可以帮助开发者快速构建启动命令,并且帮助你组织命令的参数、以及输出列表等。 commons-cli 支持以下风格的命令行参数解析: POSIX 风格 如: tar -zxvf foo.tar.gz GNU 长参数风格: du --human-readable --max-depth=1 Java 属性风格: java -Djava... 阅读详情

相关推荐

Common CLI1.2

Common CLI是一个简单的用于处理命令行参数的包,在自己的工程中引用它就行了

Common CLI

1.Commons CLI Apache Commons CLI提供了解析命令行参数的API。它也可以在命令行打印详细的参数信息。官网教程:http://commons.apache.org/proper/commons-cli/usage.html,Commons CLI的Javadoc:http://commons.apache.org/proper/commons-cli/javadocs...

GatsbyNewton 3226

使用Apache commons-cli包进行命令行参数解析的示例代码

Apache的commons-cli包是专门用于解析命令行参数格式的包。这篇文章给大家介绍使用Apache commons-cli包进行命令行参数解析的示例代码,感兴趣的朋友跟随脚本之家小编一起学习吧

Commons CLI 示例

概述 在定时任务中,经常需要通过shell脚本调起各种任务,如图所示:具体的任务实现需要定义一套CLI(命令行接口)。所谓的CLI,就是编写一套命令行接口,然后通过解析命令行,将参数传递给我们的程序去执行相应的任务。最常见的就是我们的java命令,例如:这个java -version就是一个命令行,其中-vresion就是选项。CLI共分为三个阶段,1-定义阶段,2-解析阶段,3-询问阶段,其中定...

GAMELOFT9----纸上得来终觉浅,绝知此事要躬行 894

2025年北京市职工职业技能大赛第六届信息通信行业网络安全技能大赛复赛CTF部分WP-哥斯拉流量分析

题目没有任何提示,附件gzl.pcap解题哥斯拉流量300多KB包很多,没啥经验只能挨个看回来之后又狠狠得撸了一把哥斯拉流量分析我这里用的是哥斯拉4.0.1测试链接这里发了两个包,我们进行分析。

深耕网络安全领域,聚焦护网行动(HW)、渗透测试、等级保护(等保)、CTF 竞赛四大核心方向,提供技术干货、实战经验与行业洞察。 1812

树莓派4B(Raspbian buster系统)安装ROS Melodic(附带网络配置和远程桌面控制说明)

树莓派4B(Raspbian buster系统)安装ROS Melodic(附带网络配置和远程桌面控制说明) 一、硬件准备 二、软件准备 三、安装前的准备工作 四、开始ROS的安装 五、运行小乌龟 由于坑比较多希望大家安装的时候尽量不要跳步进行,一定要等每一步运行成功了再往下进行。 一、硬件准备 1、树莓派4B一个 2、SD卡一张(最好是16G以上的我的是用的64G的) 3、显示器、键盘、鼠标 二、软件准备 1、Raspberryimage (写系统使用的) 链接:https://pan.baidu.com

weixin_45315065的博客 1万+

Apache Common CLI 如何实现命令行解析

Apache Commons CLI 提供了一个解析传递给程序的命令行选项的 API 类库。此外它还能够打印帮助消息,详细说明命令行工具的可用选项。

SmartSi 997

银河麒麟V10系统下,手把手解决Ollama安装报错‘GLIBCXX_3.4.25 not found’

本文详细介绍了在银河麒麟V10系统下解决Ollama安装报错‘GLIBCXX_3.4.25 not found’的实战指南。通过隔离编译新版libstdc++、环境变量引导和服务化封装等安全方案,确保在不破坏系统稳定性的前提下顺利运行Ollama,适用于国产操作系统与AI工具的兼容性需求。

weixin_42556197的博客 484

Commons CLI 使用介绍

Commons CLI 是一个用于表示、处理和验证命令行参数工具的API。 有时候启动一个程序,我们会在命令行设置参数,例如启动 RocketMQ 的 Broker 服务 public static void main(String[] args) { // args = {"-c","E:\sourceCode\rocketmq\conf\broker.conf","-n","192.168...

mbtlami 2954

利用Ghidra与SVD插件实现STM32固件深度逆向分析

本文详细介绍了如何利用Ghidra逆向工程框架结合SVD插件,实现对STM32固件(.bin文件)的深度逆向分析。通过加载描述芯片外设寄存器的SVD文件,Ghidra能将晦涩的硬件地址操作转换为可读的寄存器符号,极大提升了对嵌入式固件中通信协议、安全校验等关键逻辑的分析效率。文章涵盖了从Java环境搭建、工具配置到实战逆向解析的完整流程。

peach的博客 944

西门子交换机环网冗余设置(实战篇2.2)

MRP的重组时间为 200ms 因此 PROFINET 通信必须选择大于 200ms 的看门狗时间,看门狗。ET200SP默认为 2ms*3=6ms) MRP 的重组时间为 200ms 故系统会报出看门狗超时。更新,默认是 3 个周期,超出设置的周期数就会报 IO 设备故障。时间不是直接配置的,而是作为没有 IO 数据可接受的更新周期,也就是允许几个周期没有数据。来达到大于 200ms 的看门狗时间的要求(看门狗时间 可接受更新周期数 更新时间)。是IO 控制器和 IO 设备)

weixin_42580591的博客 366

Apache-common 包之 common-cli 笔记

Apache-common 包之 common-cli 笔记

蜡笔小辛的专栏 1万+

安装Office程序时无法安装的解决方案

本文主要介绍了安装Office程序时无法安装的解决方案,希望能对安装Office的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案 2.1 前置步骤 2.2 方法一 2.3 方法二

weixin_43178406的博客 15万+

apache-common-cli

package com.cli; import org.apache.commons.cli.*; import org.apache.commons.math3.random.AbstractRandomGenerator; public class test { public static void main(String[] args) throws ParseException { CommandLine cmdlines = cmdLine(a...

bck1453925668的博客 194

【Claude Code 实战】第十章:DevOps 与 CI/CD 集成 / 光子AI

本章摘要:探讨Claude Code在DevOps与CI/CD集成中的应用。DevOps作为现代软件工程核心,结合AI技术实现自动化全流程,从代码提交到生产部署。通过CALMS模型(文化、自动化、精益、度量、分享)解析DevOps理念,对比传统瀑布模式与DevOps模式差异,展示AI如何加速Dockerfile编写、CI/CD配置等任务。典型示例显示AI可将原本30-60分钟的手动配置缩短至1-2分钟,大幅提升DevOps效率。

AI天才研究院 367

易盾滑块的js逆向分析

基于易盾的滑块验证码进行逆向分析,最种实现全系列的验证码逆向,包括滑块、点选、推理拼图等多种类型。

shanf7921的博客 3万+

Apache Common CLI学习笔记

在IDEA的run configuration里面,可以通过Program arguments设置相应参数,向程序中传入信息。程序中对信息的解析,可以使用Apache Commons CLI。 Apache Commons CLI为解析传递给程序的命令行选项(command line options)提供了API,它可以帮助开发者快速构建启动命令。即编写一套命令行接口,然后通过解析命令行,将参数...

u014418064的博客 1250

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

java apache cli,《Apache Common CLI官方文档》,

《Apache Common CLI官方文档》,原文链接 参考链接 译者:小村长本篇文章是悦橙教程组织的一次Apache Common组件翻译的一部分,因为无意中看到了Apache Common CLI感觉很好奇,因为这个工具很少在网上看到,当然或许我没有关注过。因为我之前也写过类似的CLI工具所以感觉情有独钟吧。所以让我来为大家揭开CLI的神秘面纱。虽然各种人机交互技术飞速发展,...

weixin_28686771的博客 205

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

linux中common命令,使用 Apache Commons CLI 开发命令行工具

虽然各种人机交互技术飞速发展,但最传统的命令行模式依然被广泛应用于各个领域:从编译代码到系统管理,命令行因其简洁高效而备受宠爱。各种工具和系统都提供了详尽的使用手册,有些还提供示例说明如何二次开发。然而关于如何开发一个易用、强壮的命令行工具的文章却很少。本文将结合 Apache Commons CLI,通过一个完整的例子展示如何准备、开发、测试一个命令行工具。希望本文对有相关需求的读者能有所帮助。...

weixin_30229479的博客 441

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

初识 Apache Commons jar 包

长篇预警 ,要有耐心才能看下去1.1. 开篇      在Java的世界,有很多(成千上万)开源的框架,有成功的,也有不那么成功的,有声名显赫的,也有默默无闻的。在我看来,成功而默默无闻的那些框架值得我们格外的尊敬和关注,Jakarta Commons就是这样的一个框架。如果你至少参与了一个中型规模的Java项目,那么我想有超过一大半的机会你都接触和使用到了Jakarta Commons,不管你自...

改变ing 8527

apache common简介1

Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动。我选了一些比较常用的项目做简单介绍。文中用了很多网上现成的东西,我只是做了一个汇总整理。   一、Commons BeanUtils   http://jakarta.apache.org/commons/beanutils/index.html   说明:针对Bean的一个工具集。

screensky的专栏 2708

Apache Common包介绍

吐槽一下Apache的官网还需要翻墙,学会科学上网真的很重要ORZ 一、Commons BeanUtils http://jakarta.apache.org/commons/beanutils/index.html 说明:针对Bean的一个工具集。由于Bean往往是有一堆get和set组成,所以BeanUtils也是在此基础上进行一些包装。 使用示例:功能有很多,网站上有详细介绍。一个比较常用的...

tinysakura的博客 3591

apache commons cli 使用说明

概念说明Apache Commons CLI 简介 Apache Commons CLI 是 Apache 下面的一个解析命令行输入的工具包,该工具包还提供了自动生成输出帮助文档的功能。 Apache Commons CLI 支持多种输入参数格式,主要支持的格式有以下几种: 1....

chuohanwan1259的博客 1177

apache common简介

Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动。我选了一些比较常用的项目做简单介绍。文中用了很多网上现成的东西,我只是做了一个汇总整理。  一、Commons BeanUtils  http://jakarta.apache.org/commons/beanutils/index.html  说明:针对Bean的一个工具集。由于Bean往往是...

let's go 845

Apache Commons CLI 的运用

在学习Mahout中Kmeans源码中,了解了大概的结构,了解到对于输入接口,Mahout应该是在apache的Options(org.apache.commons.cli)基础上,实现了自己的Options(org.apache.commons.cli2)。查阅相关资料,大致了解了apache的Options,写了个简单的例子。   package Etl; import org...

u010961419的博客 376

java commons cli_在指定附加值时Java Apache Common CLI双精灵选项失败

仅供参考:我在Windows计算机上运行此Java程序。我相信这很重要。在指定附加值时Java Apache Common CLI双精灵选项失败基本上,我有一个问题,指定一个值到双连字符的选项。单连字选项正常工作。import org.apache.commons.cli.*;public class Test {public static void main(String[] args) thr...

weixin_35915120的博客 974
上一篇: Log4j的使用
下一篇: 给log4j配置数据库连接
socoolfj
博客等级 码龄21年 9粉丝 52原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值