1 /*************************************************************************************** 2 * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. * 3 * http://aspectwerkz.codehaus.org * 4 * ---------------------------------------------------------------------------------- * 5 * The software in this package is published under the terms of the LGPL license * 6 * a copy of which has been included with this distribution in the license.txt file. * 7 **************************************************************************************/ 8 package org.codehaus.aspectwerkz.hook; 9 10 import java.io.File; 11 import java.io.IOException; 12 13 /*** 14 * Base class for JVM Process based starter. <p/>Base implementation to lauch a JVM given java options, main class and 15 * args in a separate process. 16 * 17 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a> 18 */ 19 abstract class AbstractStarter { 20 protected String opt; 21 22 protected String main; 23 24 protected AbstractStarter(String opt, String main) { 25 this.opt = opt; 26 this.main = main; 27 } 28 29 /*** 30 * return command line that launched the target process 31 */ 32 public String getCommandLine() { 33 StringBuffer command = new StringBuffer(); 34 command.append(System.getProperty("java.home")); 35 command.append(File.separatorChar).append("bin").append(File.separatorChar).append("java"); 36 command.append(" ").append(opt); 37 command.append(" ").append(main); 38 return command.toString(); 39 } 40 41 /*** 42 * launchs target process 43 */ 44 public Process launchVM() throws IOException { 45 System.out.println(getCommandLine()); 46 return Runtime.getRuntime().exec(getCommandLine()); 47 } 48 }