public static void main(String[] args) { System.setProperty( RemotingCommand.RemotingVersionKey, Integer.toString(MQVersion.CurrentVersion)); try { initLogback(); switch (args.length) { case 0: printHelp(); break; case 2: if (args[0].equals("help")) { SubCommand cmd = findSubCommand(args[1]); if (cmd != null) { Options options = ServerUtil.buildCommandlineOptions(new Options()); options = cmd.buildCommandlineOptions(options); if (options != null) { ServerUtil.printCommandLineHelp("mqadmin " + cmd.commandName(), options); } } else { System.out.println("The sub command \'" + args[1] + "\' not exist."); } break; } case 1: default: SubCommand cmd = findSubCommand(args[0]); if (cmd != null) { // 将main中的args转化为子命令的args(去除第一个参数) String[] subargs = parseSubArgs(args); // 解析命令行 Options options = ServerUtil.buildCommandlineOptions(new Options()); final CommandLine commandLine = ServerUtil.parseCmdLine( "mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { System.exit(-1); return; } if (commandLine.hasOption('n')) { String namesrvAddr = commandLine.getOptionValue('n'); System.setProperty(MixAll.NAMESRV_ADDR_PROPERTY, namesrvAddr); } cmd.execute(commandLine, options); } else { System.out.println("The sub command \'" + args[0] + "\' not exist."); } break; } } catch (Exception e) { e.printStackTrace(); } }