public class QuickstartJava extends Java {
public int executeJava() throws BuildException {
CommandlineJava cmdl = getCommandLine();
final Process process;
final ExecuteStreamHandler streamHandler = redirector.createHandler();
final int freePort = findFreePort();
setupRedirector();
try {
cmdl.createArgument().setValue("exit-port=" + freePort);
process = Execute.launch(getProject(), cmdl.getCommandline(), null, getProject().getBaseDir(), true);
startStreamHandler(streamHandler, process);
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
signalExit(freePort);
waitForProcessShutdown(process);
streamHandler.stop();
Execute.closeStreams(process);
}
});
} catch (IOException e) {
throw new BuildException("Failed to launch Quickstart processes.", e);