Map<String, String> envVariables) throws IOException, InterruptedException {
String displayName = "Selenium RC";
ClasspathBuilder classpath = new ClasspathBuilder().add(standaloneServerJar);
JVMBuilder vmb = new JVMBuilder();
vmb.systemProperties(properties);
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress("localhost", 0));
serverSocket.setSoTimeout(10000);
// use -cp + FQCN instead of -jar since remoting.jar can be rebundled
// (like in the case of the swarm plugin.)
vmb.classpath().addJarOf(Channel.class);
vmb.mainClass(Launcher.class);
if (classpath != null)
vmb.args().add("-cp").add(classpath);
vmb.args().add("-connectTo", "localhost:" + serverSocket.getLocalPort());
// TODO add XVFB options here
Proc p = vmb.launch(new LocalLauncher(listener)).stdout(listener).envs(envVariables).start();
Socket s = serverSocket.accept();
serverSocket.close();
return Channels.forProcess("Channel to " + displayName, Computer.threadPoolForRemoting, new BufferedInputStream(new SocketInputStream(s)),