KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > hook > AbstractStarter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.hook;
5
6 import java.io.File JavaDoc;
7 import java.io.IOException JavaDoc;
8
9 /**
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 JavaDoc opt;
17
18   protected String JavaDoc main;
19
20   protected AbstractStarter(String JavaDoc opt, String JavaDoc 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 JavaDoc getCommandLine() {
29     StringBuffer JavaDoc command = new StringBuffer JavaDoc();
30     command.append(System.getProperty("java.home"));
31     command.append(File.separatorChar).append("bin").append(File.separatorChar).append("java");
32     command.append(" ").append(opt);
33     command.append(" ").append(main);
34     return command.toString();
35   }
36
37   /**
38    * launchs target process
39    */

40   public Process JavaDoc launchVM() throws IOException JavaDoc {
41     System.out.println(getCommandLine());
42     return Runtime.getRuntime().exec(getCommandLine());
43   }
44 }
Popular Tags