I'm writing a wrapper application that will be used to provide an abstraction layer around an existing application that is currently called from the command line. How would I go about calling the main method in the existing app from within my wrapper app?
+5
A:
Java main methods are static, so you could just call it as:
import other.app.package.name;
...
String[] args;
// Create/populate args here
ClassNameHere.main(args);
Of course, this is assuming you looked at the other application's manifest file to see which class main resides in.
Set args
to whatever you would usually pass in on the command line.
R. Bemrose
2009-10-26 14:17:45
Also include possible command line arguments (entered as an array of strings).
Kathy Van Stone
2009-10-26 14:20:13
@Kathy: I was just adding something in when you said that. I hadn't thought about main taking a String array when I originally posted.
R. Bemrose
2009-10-26 14:22:12
Thank you - just what I needed.
davek
2009-10-26 14:29:30
Note that if you need to isolate/differentiate the classes used by the application, you should load the application class through a dedicated classloader and then reflect over the Class instance to obtain main method.
2009-10-26 14:55:43