When calling the main method of a Java class from another main method using reflection,
Class thisClass = loader.loadClass(packClassName);
Method thisMethod
For your stated requirements (dynamically invoke the main method of a random class, with reflection you have alot of unnecessary code.
You can adapt the following code to meet your needs:
try {
final Class> clazz = Class.forName("blue.RandomClass");
final Method method = clazz.getMethod("main", String[].class);
final Object[] args = new Object[1];
args[0] = new String[] { "1", "2"};
method.invoke(null, args);
} catch (final Exception e) {
e.printStackTrace();
}