欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java 命令行参数真简单

程序员文章站 2022-07-14 21:40:34
...
public class Main {

@Parameter (
names = {"--host"},
description = "Server host name or ip address"
)
private String host = null;

@Parameter (
names = {"--port"},
description = "Server port"
)
private int port = 8080;

@Parameter (
names = {"--context-path"},
description = "Context path"
)
private String contextPath = "/openscoring";

@Parameter (
names = {"--model-dir"},
description = "Model auto-deployment directory"
)
private File modelDir = null;

@Parameter (
names = {"--console-war"},
description = "Console web application (WAR) file or directory",
hidden = true
)
private File consoleWar = null;

@Parameter (
names = {"--help"},
description = "Show the list of configuration options and exit",
help = true
)
private boolean help = false;


static
public void main(String... args) throws Exception {
Main main = new Main();

JCommander commander = new JCommander(main);
commander.setProgramName(Main.class.getName());

try {
commander.parse(args);
} catch(ParameterException pe){
commander.usage();

System.exit(-1);
}

if(main.help){
commander.usage();

System.exit(0);
}

}
}
相关标签: java