ITeye博客

java 命令行参数真简单

poson · 2014-11-11 17:55 · java · 编程语言 · Markdown

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);
	}

}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。