java 命令行参数真简单_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java 命令行参数真简单

java 命令行参数真简单

 2014/11/11 19:26:55  poson  程序员俱乐部  我要评论(0)
  • 摘要:publicclassMain{@Parameter(names={"--host"},description="Serverhostnameoripaddress")privateStringhost=null;@Parameter(names={"--port"},description="Serverport")privateintport=8080;@Parameter(names={"--context-path"},description="Contextpath"
  • 标签:Java 命令
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);
}

}
}
发表评论
用户名: 匿名