KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > hook > AbstractStarter


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 JavaDoc;
11 import java.io.IOException JavaDoc;
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 JavaDoc opt;
21
22     protected String JavaDoc main;
23
24     protected AbstractStarter(String JavaDoc opt, String JavaDoc 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 JavaDoc getCommandLine() {
33         StringBuffer JavaDoc command = new StringBuffer JavaDoc();
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 JavaDoc launchVM() throws IOException JavaDoc {
45         System.out.println(getCommandLine());
46         return Runtime.getRuntime().exec(getCommandLine());
47     }
48 }
Popular Tags