01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.hook;
05:
06: import java.io.File;
07: import java.io.IOException;
08:
09: /**
10: * Base class for JVM Process based starter. <p/>Base implementation to lauch a JVM given java options, main class and
11: * args in a separate process.
12: *
13: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
14: */
15: abstract class AbstractStarter {
16: protected String opt;
17:
18: protected String main;
19:
20: protected AbstractStarter(String opt, String main) {
21: this .opt = opt;
22: this .main = main;
23: }
24:
25: /**
26: * return command line that launched the target process
27: */
28: public String getCommandLine() {
29: StringBuffer command = new StringBuffer();
30: command.append(System.getProperty("java.home"));
31: command.append(File.separatorChar).append("bin").append(
32: File.separatorChar).append("java");
33: command.append(" ").append(opt);
34: command.append(" ").append(main);
35: return command.toString();
36: }
37:
38: /**
39: * launchs target process
40: */
41: public Process launchVM() throws IOException {
42: System.out.println(getCommandLine());
43: return Runtime.getRuntime().exec(getCommandLine());
44: }
45: }
|