Re: Launch a new java app from a java program
Yao Qi wrote:
I want to write a java program A to launch another java app B.
see http://mindprod.com/jgloss/exec.html
Yeah, that is what I want to find.
Really? exec seems a heavy handed way to start
a new Java app. running. Generally I would import
the Java class and instantiate it normally, or call its
main with args if needed.
If the class is not known until runtime, then perhaps
reflection can do the trick..
<sscce>
class A {
String[] args = {
"a","b","c"
};
A() throws Exception {
Class bClass = this.getClass().forName("B");
B b = (B)bClass.newInstance();
b.main(args);
}
public static void main(String[] args)
throws Exception {
A a = new A();
}
}
class B {
public static void main(String[] args) {
System.out.println("args: ");
for (int ii=0; ii< args.length; ii++) {
System.out.println(args[ii]);
}
}
}
</sscce>
..though I am not yet convinced that either exec
or reflection is needed for this task.
Tell us - why can you not simply import class B
into your code?
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200706/1