views:

74

answers:

1

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
Also include possible command line arguments (entered as an array of strings).
Kathy Van Stone
@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
Thank you - just what I needed.
davek
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.