Here you can find the source of invokeMain(Class> mainClass, List
invokeMain.
Parameter | Description |
---|---|
mainClass | a java.lang.Class object. |
args | a java.util.List object. |
Parameter | Description |
---|
public static void invokeMain(Class<?> mainClass, List<String> args) throws Exception
//package com.java2s; /**/*from ww w . j a va2 s. c om*/ * Copyright (c) 2009 Pyxis Technologies inc. * * This 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. * * This software 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, * or see the FSF site: http://www.fsf.org. * * @author oaouattara * @version $Id: $Id */ import java.lang.reflect.Method; import java.util.List; public class Main { /** * <p>invokeMain.</p> * * @param mainClass a {@link java.lang.Class} object. * @param args a {@link java.util.List} object. * @throws java.lang.Exception if any. */ public static void invokeMain(Class<?> mainClass, List<String> args) throws Exception { Method mainMethod = mainClass.getMethod("main", Class.forName("[Ljava.lang.String;")); mainMethod.invoke(null, convertToArray(args)); } private static Object convertToArray(List<String> args) { String[] array = new String[args.size()]; args.toArray(array); return array; } }