Code below shows how to launch an application from another application dynamically.
public class Program1b {
public static void main(String arg[]) {
System.out.println("Hello from Program1b");
new Program1b().execute("Program2");
}
public void execute(String name) {
Class params[] = {String[].class};
// if you need parameters
// String[] args = new String[] { "Hello", "world" };
// Class params[] = new Class[] { args.getClass() });
try {
Class.forName(name).
getDeclaredMethod("main", params).
invoke(null, new Object[] {new String[] {}});
}
catch(Exception e){ e.printStackTrace();}
}
}