Source Code : Show loading a class and finding and calling its Main method

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Show loading a class and finding and calling its Main method

Show loading a class and finding and calling its Main method
        

import java.lang.reflect.Method;

/**
 * Show loading a class and finding and calling its Main method.
 * 
 * @author Ian F. Darwin, http://www.darwinsys.com/
 * @version $Id: InvokeMain.java,v 1.3 2004/02/09 03:33:54 ian Exp $
 */
public class InvokeMain {
  public static void main(String[] argv) {
    //+
    try {
      // First, find the class.
      Class c = Class.forName("InvokeMain"); // RECURSION
      System.out.println(c);

      // Create the array of Argument Types
      Class[] argTypes = { argv.getClass(), // array is Object!
      };

      // Now find the method
      Method m = c.getMethod("main", argTypes);
      System.out.println(m);

      // Create the actual argument array
      Object passedArgv[] = { argv };

      // Now invoke the method.
      m.invoke(null, passedArgv);

    } catch (Exception e) {
      System.err.println(e);
    }
    //-
  }
}


           
         
    
    
    
    
    
    
    
  

Thank with us