You can create your own startup mechanism, but I'm not sure why you want it.
public class RunTests { public static void main(String... args) throws ClassNotFoundException { List<Class> classes = new ArrayList<Class>(); try { for (String arg : args) { classes.add(Class.forName(arg)); } } catch (ClassNotFoundException e) { if (classes.isEmpty()) throw e; } String[] remainingArgs = Arrays.asList(args).subList(classes.size(), args.length).toArray(new String[0]); for(Class clazz: classes) { try { Test test = (Test) clazz.newInstance(); test.main(remainingArgs); test.display(); } catch (Exception e) { e.printStackTrace(); } } } } interface Test { public void main(String... args); public void display(); }
BTW: you do not need to have a main () method, for example
class NoMain { static { System.out.println("Hello World"); System.exit(0); } }
compiles and runs without errors.
source share