Java command line program build tool-airline
In the past, I used to develop Java command line programs. I had a lot of trouble parsing parameters and some help information, today, when studying the interface test, I accidentally discovered a tool that allows you to quickly build a command line program.
Github address
Airline
Import jar package
Airline jar
Search for statements suitable for your system building in the maven Repository
Code
I found an explanation.har
File project to explain the development process
Customize your own command line
My command line usesdoctorq
As a command, the parameter iscompany
The complete command format should bedoctorq company XXXXX
.
@ Command (name = "doctorq", description = "test for cli") public class Doctorq implements Runnable {@ Arguments private String company;/* (non-Javadoc) * @ see java. lang. runnable # run () */@ Override public void run () {// TODO Auto-generated method stub System. out. println ("Doctorq belongs to" + company );}}
main
Function
public class HarCli { public static void main(String[] args) { @SuppressWarnings("unchecked") CliBuilder
builder = Cli.
builder("har") .withDescription("HAR power tool") .withDefaultCommand(Help.class) .withCommands(Help.class, Doctorq.class); Cli
cliParser = builder.build(); try { cliParser.parse(args).run(); } catch(ParseArgumentsUnexpectedException e) { System.out.println("Invalid command, use '$ har help' for usage instructions!"); } }}
Run
I am using a maven project. For the configuration, see how to package the maven project into an executable jar file.
Eclipse
PointRun
The following information is output:
Jar package execution
First package:mvn package
After execution, a jar package is generated under the target directory of the root directory.
Go to the target package and run the following command: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwPjxpbWcgYWx0PQ = "here write picture description" src = "http://www.bkjia.com/uploads/allimg/160122/04230440L-3.png" title = ""/>