Java Reflection Method Main Invoke invokeMain(Class fooClass)

Here you can find the source of invokeMain(Class fooClass)

Description

invoke Main

License

Apache License

Declaration

public static void invokeMain(Class<?> fooClass) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {
    public static void invokeMain(Class<?> fooClass) throws Exception {
        System.out.println();/* www.ja  v a 2 s.  c  o m*/
        System.out.println(fooClass.getName() + " loaded by " + fooClass.getClassLoader());

        Method main = fooClass.getMethod("main", String[].class);
        System.out.println("Get method: " + main);

        Object ret = main.invoke(null, new Object[] { new String[] { "a", "b", "c" } });
        System.out.printf("Return is %s\n", ret);
    }
}

Related

  1. invoke(String property, Object main)
  2. invokeMain(Class clazz, String[] args)
  3. invokeMain(Class mainClass, List args)
  4. invokeMain(ClassLoader classloader, String classname, String[] args)
  5. invokeMain(Method main, String[] args)
  6. invokeMain(String className, String[] args, ClassLoader classLoader)