我正在为MQ客户端编写Java客户端程序,以执行初始测试,为此我需要传递以下参数,如下所示:
样例命令行参数
// -h 127.0.0.1 -p 1414 -c CLIENT.CHANNEL -m A1 -q TEST.QUEUE
在月食中。
当我在eclipse中的程序参数中传递值时,我得到了IllegalArgumentException
。如何传递以上参数,请帮助我。
我的代码:
private void init(String[] args) throws IllegalArgumentException {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
...
params = new Hashtable<String, String>();
if (args.length > 0 && (args.length % 2) == 0) {
for (int i = 0; i < args.length; i += 2) {
params.put(args[i], args[i + 1]);
}
} else {
throw new IllegalArgumentException();
}
if (allParamsPresent()) {
qMgrName = (String) params.get("-m");
System.out.println("qMgrName: " + qMgrName);
outputQName = (String) params.get("-q");
System.out.println("outputQName: " + outputQName);
replytoQueueName = (String) params.get("-r");
System.out.println("replytoQueueName: " + replytoQueueName);
url = (String) params.get("-j");
System.out.println("url: " + url);
username = (String) params.get("-u");
System.out.println("username: " + username);
password = (String) params.get("-pp");
System.out.println("password: " + password);