Java Reflection Method Main Invoke invokeMain(ClassLoader classloader, String classname, String[] args)

Here you can find the source of invokeMain(ClassLoader classloader, String classname, String[] args)

Description

invoke Main

License

LGPL

Declaration

private static void invokeMain(ClassLoader classloader,
            String classname, String[] args) throws IllegalAccessException,
            InvocationTargetException, NoSuchMethodException,
            ClassNotFoundException 

Method Source Code

//package com.java2s;
/*//from  w w w. j  av  a 2s.c om
 *   This software is distributed under the terms of the FSF
 *   Gnu Lesser General Public License (see lgpl.txt).
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    private static void invokeMain(ClassLoader classloader,
            String classname, String[] args) throws IllegalAccessException,
            InvocationTargetException, NoSuchMethodException,
            ClassNotFoundException {
        Class<?> invoked_class = classloader.loadClass(classname);
        Class<?>[] method_param_types = new Class[1];
        method_param_types[0] = args.getClass();
        Method main = invoked_class.getDeclaredMethod("main",
                method_param_types);
        Object[] method_params = new Object[1];
        method_params[0] = args;

        main.invoke(null, method_params);
    }
}

Related

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