Java Utililty Methods Reflection Method Main Invoke

List of utility methods to do Reflection Method Main Invoke

Description

The list of methods to do Reflection Method Main Invoke are organized into topic(s).

Method

Objectinvoke(String property, Object main)
invoke
Method m;
try {
    try {
        m = main.getClass()
                .getMethod("get" + property.substring(0, 1).toUpperCase() + property.substring(1));
    } catch (NoSuchMethodException ex) {
        try {
            m = main.getClass()
...
voidinvokeMain(Class clazz, String[] args)
invoke Main
if (clazz == null) {
    throw new IllegalArgumentException("clazz is not given");
Method method = null;
try {
    Class[] argTypes = new Class[] { String[].class };
    method = clazz.getDeclaredMethod("main", argTypes);
} catch (NoSuchMethodException ex) {
...
voidinvokeMain(Class fooClass)
invoke Main
System.out.println();
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);
voidinvokeMain(Class mainClass, List args)

invokeMain.

Method mainMethod = mainClass.getMethod("main", Class.forName("[Ljava.lang.String;"));
mainMethod.invoke(null, convertToArray(args));
voidinvokeMain(ClassLoader classloader, String classname, String[] args)
invoke Main
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);
voidinvokeMain(Method main, String[] args)
invoke Main
try {
    if (main.getParameterTypes().length != 0) {
        main.invoke(null, new Object[] { args });
    } else {
        main.invoke(null, new Object[] {});
} catch (IllegalArgumentException e) {
    System.err.println("instanceAUTbyMain err:" + e.getMessage());
...
voidinvokeMain(String className, String[] args, ClassLoader classLoader)
Invokes the application in this jar file given the name of the main class and an array of arguments.
Class<?> clazz = classLoader.loadClass(className);
Method method = clazz.getMethod("main", new Class[] { args.getClass() });
method.setAccessible(true);
int mods = method.getModifiers();
if (method.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) {
    throw new NoSuchMethodException("main");
try {
...
voidinvokeMain(String... args)
invoke Main
try {
    Class<?> c = Class.forName(args[0]);
    Class<String[]> argTypes = String[].class;
    Method main = c.getDeclaredMethod("main", argTypes);
    Object mainArgs = Arrays.copyOfRange(args, 1, args.length);
    System.out.format("invoking %s.main()%n", c.getName());
    main.invoke(null, mainArgs);
} catch (Exception ex) {
...