addShutdownHook(); // handle Ctrt-C.
gf = GlassFishRuntime.bootstrap().newGlassFish();
gf.start();
CommandRunner cr = gf.getCommandRunner();
while (true) {
System.out.print("\n\nGlassFish $ ");
String str = null;
try {
str = new BufferedReader(new InputStreamReader(System.in)).readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (str != null && str.trim().length() != 0) {
if ("exit".equalsIgnoreCase(str) || "quit".equalsIgnoreCase(str)) {
break;
}
String[] split = str.split(" ");
String command = split[0].trim();
String[] commandParams = null;
if (split.length > 1) {
commandParams = new String[split.length - 1];
for (int i = 1; i < split.length; i++) {
commandParams[i - 1] = split[i].trim();
}
}
try {
CommandResult result = commandParams == null ?
cr.run(command) : cr.run(command, commandParams);
System.out.println("\n" + result.getOutput());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}