java 命令行参数真简单
程序员文章站
2022-07-14 21:40:10
...
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);
}
}
}
@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);
}
}
}
上一篇: 《操作系统》第四次实验——页面置换
下一篇: [转]40个重要的HTML5面试题及答案