An annotation based command line parser
Java命令行选项解析之Commons-CLI & Args4J & JCommander
http://rensanning.iteye.com/blog/2161201
JCommander star1000+
This is an annotation based parameter parsing framework for Java 8.
Here is a quick example:
public class JCommanderTest {
@Parameter
public List<String> parameters = Lists.newArrayList();
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
public Integer verbose = 1;
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
public String groups;
@Parameter(names = "-debug", description = "Debug mode")
public boolean debug = false;
@DynamicParameter(names = "-D", description = "Dynamic parameters go here")
public Map<String, String> dynamicParams = new HashMap<String, String>();
}
and how you use it:
JCommanderTest jct = new JCommanderTest();
String[] argv = { "-log", "2", "-groups", "unit1,unit2,unit3",
"-debug", "-Doption=value", "a", "b", "c" };
JCommander.newBuilder()
.addObject(jct)
.build()
.parse(argv); Assert.assertEquals(2, jct.verbose.intValue());
Assert.assertEquals("unit1,unit2,unit3", jct.groups);
Assert.assertEquals(true, jct.debug);
Assert.assertEquals("value", jct.dynamicParams.get("option"));
Assert.assertEquals(Arrays.asList("a", "b", "c"), jct.parameters);
The full doc is available at http://jcommander.org.
Argparse4j is a command line argument parser library for Java based on Python's argparse module.
Argparse4j is available in Maven central repository:
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
<version>0.8.0</version>
</dependency>
https://github.com/jankroken/commandline
The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool.
Commons CLI supports different types of options:
http://commons.apache.org/proper/commons-cli/
https://stackoverflow.com/questions/11704338/java-cli-commandlineparser
https://github.com/jatoben/CommandLine
https://github.com/apache/commons-cli
CLI Parser is a tiny (10k jar), super easy to use library for parsing various kinds of command line arguments or property lists. Using annotations on your fields or JavaBean properties you can specify what configuration is available. Here is an example:
public class Loader {
@Argument
private static Boolean hdfs = false;
@Argument(alias = "r", description = "Regular expression to parse lines", required = true)
private static String regex;
@Argument(alias = "k", description = "Key column", required = true)
private static String key;
@Argument(alias = "p", description = "Key prefix")
private static String prefix;
@Argument(alias = "c", description = "Column groups", delimiter = ",")
private static String[] columns;
@Argument(alias = "n", description = "Column names", delimiter = ",")
private static String[] names;
@Argument(alias = "h", description = "Redis host")
private static String host = "localhost";
@Argument(alias = "p", description = "Redis port")
private static Integer port = 6379;
public static void main(String[] args) throws IOException {
// unparsed will contain all unparsed arguments to the command line
List<String> unparsed = Args.parseOrExit(Loader.class, args);
// Loader's fields will be populated after this line or the program will exit with usage
}
}
In this case we are configuring static fields, but you can also use the same system with instances. If you pass in a wrong command line argument you will get the usage message:
Usage: com.sampullara.cli.Example
-hdfs [flag]
-regex (-r) [String] Regular expression to parse lines
-key (-k) [String] Key column
-prefix (-p) [String] Key prefix
-columns (-c) [String[,]] Column groups
-names (-n) [String[,]] Column names
-host (-h) [String] Redis host (localhost)
-port (-p) [Integer] Redis port (6379)
That message will print out the names and aliases of the arguments, type, description and a default value for the parameter if there is one. You can add it to your code with:
<dependency>
<groupId>com.github.spullara.cli-parser</groupId>
<artifactId>cli-parser</artifactId>
<version>1.1</version>
</dependency>
https://github.com/spullara/cli-parser
KeyStore Explorer is a free GUI replacement for the Java command-line utilities keytool and jarsigner.
Official website: http://keystore-explorer.org/
Features:
- Create, load, save and convert between various KeyStore types: JKS, JCEKS, PKCS#12, BKS (V1 and V2) and UBER
- Change KeyStore and KeyStore entry passwords
- Delete or rename KeyStore entries
- Cut/copy/paste KeyStore entries
- Append certificates to key pair certificate chains
- Generate RSA, ECC and DSA key pairs with self-signed X.509 certificates
- Apply X.509 certificate extensions to generated key pairs and Certificate Signing Requests (CSRs)
- View X.509 Certificate, CRL and CRL entry X.509 V3 extensions
- Import and export keys and certificates in many formats: PKCS#12, PKCS#8, PKCS#7, DER/PEM X.509 certificate files, Microsoft PVK, SPC, PKI Path, OpenSSL
- Generate, view and sign CSRs in PKCS #10 and SPKAC formats
- Sign JAR files
- Configure a CA Certs KeyStore for use with KeyStore operations
https://github.com/kaikramer/keystore-explorer
Library Usage:
- Drop the jar into your lib folder and add to build path.
- Choose the converter of your choice, they are named DocToPDFConverter, DocxToPDFConverter, PptToPDFConverter, PptxToPDFConverter and OdtToPDFConverter.
- Instantiate with 4 parameters
- InputStream
inStream: Document source stream to be converted - OutputStream
outStream: Document output stream - boolean
showMessages: Whether to show intermediate processing messages to Standard Out (stdout) - boolean
closeStreamsWhenComplete: Whether to close input and output streams when complete
- InputStream
- Call the "convert()" method and wait.
Caveats and technical details:
This tool relies on Apache POI, xdocreport, docx4j and odfdom libraries. They are not 100% reliable and the output format may not always be what you desire.
DOC:
Generally ok but takes some time to convert.. I notice that after conversion, the paragraph spacing tends to increase affecting your page layout. Conversion is done using docx4j to convert DOC to DOCX then to PDF.(Cannot use xdocreport once the DOCX data is obtained as the intermediate data structure is docx4j specific.)
DOCX:
Very good results. Fast conversion too. Conversion is done using xdocreport library as it seems faster and more accurate than docx4j.
PPT and PPTX:
Resulting file is a PDF comprising of a PNG embedded in each page. Should be good enough for printing. This is the limitation of the Apache POI and docx4j libraries.
ODT:
Quality and speed as good as DOCX. Conversion is done using odfdom of the Apache ODF Toolkit.
Main Libraries
Apache POI: https://poi.apache.org/
xdocreport: http://code.google.com/p/xdocreport/
docx4j: http://www.docx4java.org/
odfdom: https://incubator.apache.org/odftoolkit/odfdom/
https://github.com/yeokm1/docs-to-pdf-converter
Pdf2Dom is a PDF parser that converts the documents to a HTML DOM representation. The obtained DOM tree may be then serialized to a HTML file or further processed. A command-line utility for converting the PDF documents to HTML is included in the distribution package. Pdf2Dom may be also used as an independent Java library with a standard DOM i…http://cssbox.sourceforge.net/pdf2dom/
Pdf2Dom is based on the Apache PDFBox™ library.
https://github.com/radkovo/Pdf2Dom
About
Generate scaffold with spring boot.
Generate CRUD basic with spring boot.
Scaffold for java web, a clean generate with simple classes.
https://github.com/NetoDevel/cli-spring-boot-scaffold
An annotation based command line parser的更多相关文章
- logoff remote desktop sessions via command line tools
This trick I learned from my one of ex-college. In Windows servers, only two remote desktop session ...
- 15 Examples To Master Linux Command Line History
When you are using Linux command line frequently, using the history effectively can be a major produ ...
- atprogram.exe : Atmel Studio Command Line Interface
C:\Program Files\Atmel\Atmel Studio 6.1\atbackend\atprogram.exe No command specified.Atmel Studio Co ...
- Building QT projects from the command line
/************************************************************************ * Building QT projects fro ...
- [笔记]The Linux command line
Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...
- Linux Command Line learning
https://www.codecademy.com/en/courses/learn-the-command-line Background The command line is a text i ...
- MAC OS 如何安装命令行工具:Command Line Tools
打开终端输入:xcode-select --install 回车 安装好了测试结果:gcc -v 显示如下: xcode-select: note: install requested for com ...
- Xcode 8.X Command Line Tools
Summary Step 1. Upgrade Your System to macOS Sierra Step 2. Open the Terminal Application Step 3. Is ...
- Creating Node.js Command Line Utilities to Improve Your Workflow
转自:https://developer.telerik.com/featured/creating-node-js-command-line-utilities-improve-workflow/ ...
随机推荐
- android bitmap压缩几种色彩详解
android中的大图片一般都要经过压缩才显示,不然容易发生oom,一般我们压缩的时候都只关注其尺寸方面的大小,其实除了尺寸之外,影响一个图片占用空间的还有其色彩细节. 打开Android.graph ...
- 有关java的引用传递,直接操作对象本身。直接删除BE的value中某值
HashSet<String> refRegions = BE.get(regionName); HashSet<String> values = new HashSet ...
- 面试题之C# 内存管理与垃圾回收
面试题之C# 内存管理与垃圾回收 你说说C# 的内存管理是怎么样的 这句话我记了一个多礼拜了, 自从上次东北师大面试之后, 具体请看<随便扯扯东北师大的面试>. 国庆闲着没事, 就大概了解 ...
- 3 sum closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- 简单验证码的识别:Bitmap类的使用
验证码的智能识别是一项比较复杂的工作,甚至需要掌握点图像学的知识. 当然对于写程序的来说不用那么深入,只需要掌握几个常规步骤就行了. 验证码图像识别步骤:1.获取图像 2.清除边框 3.灰度处理 4. ...
- VueJs(9)---组件(父子通讯)
组件(父子通讯) 一.概括 在一个组件内定义另一个组件,称之为父子组件. 但是要注意的是:1.子组件只能在父组件内部使用(写在父组件tempalte中); 2.默认情况下,子组件无法访问父组件上的数据 ...
- eclipse工程当中的.classpath 和.project文件什么作用?
.project是项目文件,项目的结构都在其中定义,比如lib的位置,src的位置,classes的位置.classpath的位置定义了你这个项目在编译时所使用的$CLASSPATH .classpa ...
- 电商网站开发记录(三) Spring的引入,以及配置详解
1.web.xml配置注解<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=& ...
- (七):C++分布式实时应用框架 2.0
C++分布式实时应用框架 2.0 技术交流合作QQ群:436466587 欢迎讨论交流 上一篇:(六):大型项目容器化改造 版权声明:本文版权及所用技术归属smartguys团队所有,对于抄袭,非经同 ...
- 微软黑科技强力注入,.NET C#全面支持人工智能
微软黑科技强力注入,.NET C#全面支持人工智能,AI编程领域开始C#.Py--百花齐放 就像武侠小说中,一个普通人突然得到绝世高手的几十年内力注入,招式还没学,一身内力有点方 Introducin ...