Java Reflection Method Main Invoke invokeMain(Method main, String[] args)

Here you can find the source of invokeMain(Method main, String[] args)

Description

invoke Main

License

Open Source License

Declaration

public static void invokeMain(Method main, String[] args) 

Method Source Code


//package com.java2s;
/*//from   w ww  .  j av  a  2 s  .  co m
 * Copyright (C) 2006-2009
 * Woei-Kae Chen <wkc@csie.ntut.edu.tw>
 * Hung-Shing Chao <s9598007@ntut.edu.tw>
 * Tung-Hung Tsai <s159020@ntut.edu.tw>
 * Zhe-Ming Zhang <s2598001@ntut.edu.tw>
 * Zheng-Wen Shen <zwshen0603@gmail.com>
 * Jung-Chi Wang <snowwolf725@gmail.com>
 *
 * This file is part of GTT (GUI Testing Tool) Software.
 *
 * GTT is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GTT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * GNU GENERAL PUBLIC LICENSE http://www.gnu.org/licenses/gpl
 */

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

public class Main {
    public static void invokeMain(Method main, String[] args) {
        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());
        } catch (IllegalAccessException e) {
            System.err.println("instanceAUTbyMain err:" + e.getMessage());
        } catch (InvocationTargetException e) {
            System.err.println("instanceAUTbyMain err:" + e.getMessage());
        }
    }
}

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(ClassLoader classloader, String classname, String[] args)
  6. invokeMain(String className, String[] args, ClassLoader classLoader)
  7. invokeMain(String... args)