001         package com.croftsoft.core.lang.reflect;
002    
003         import java.lang.reflect.*;
004    
005         /*********************************************************************
006         *
007         * Static library to invoke methods using reflection.
008         *
009         * @version
010         *   1998-10-04
011         * @author
012         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
013         *********************************************************************/
014    
015         public class  MethodLib
016         //////////////////////////////////////////////////////////////////////
017         //////////////////////////////////////////////////////////////////////
018         {
019    
020         private  MethodLib ( ) { }
021    
022         public static void  invokeMain ( Class  c, String [ ]  args )
023           throws IllegalAccessException
024         //////////////////////////////////////////////////////////////////////
025         {
026           Method  method;
027    
028           try
029           {
030             method = c.getMethod ( "main",
031               new Class [ ] { String [ ].class } );
032           }
033           catch ( NoSuchMethodException  ex )
034           {
035             System.err.println ( "No main() method in class \""
036               + c.getName ( ) + "\"." );
037             return;
038           }
039    
040           try
041           {
042             method.invoke ( null, new Object [ ] { args } );
043           }
044           catch ( InvocationTargetException  ex )
045           {
046             Throwable  t = ex.getTargetException ( );
047             System.err.println (
048               "\"main()\" method exited with exception \"" + t + "\"." );
049             t.printStackTrace ( );
050           }
051         }
052    
053         //////////////////////////////////////////////////////////////////////
054         //////////////////////////////////////////////////////////////////////
055         }