01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package org.codehaus.aspectwerkz.hook;
08:
09: import java.io.File;
10: import java.io.IOException;
11:
12: /**
13: * Base class for JVM Process based starter. <p/>Base implementation to lauch a JVM given java options, main class and
14: * args in a separate process.
15: *
16: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
17: */
18: abstract class AbstractStarter {
19: protected String opt;
20:
21: protected String main;
22:
23: protected AbstractStarter(String opt, String main) {
24: this .opt = opt;
25: this .main = main;
26: }
27:
28: /**
29: * return command line that launched the target process
30: */
31: public String getCommandLine() {
32: StringBuffer command = new StringBuffer();
33: command.append(System.getProperty("java.home"));
34: command.append(File.separatorChar).append("bin").append(
35: 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: }
|