File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -97,9 +97,34 @@ private ClassLoader createClassLoader(URL[] urls) {
9797 protected void launch (ClassLoader classLoader , String mainClassName , String [] args ) throws Exception {
9898 Thread .currentThread ().setContextClassLoader (classLoader );
9999 Class <?> mainClass = Class .forName (mainClassName , false , classLoader );
100- Method mainMethod = mainClass .getDeclaredMethod ("main" , String [].class );
100+
101+ Method [] methods = mainClass .getDeclaredMethods ();
102+ Method mainMethod = null ;
103+ for (Method m : methods ) {
104+ if ("main" .equals (m .getName ())) {
105+ mainMethod = m ;
106+ break ;
107+ }
108+ }
109+
110+ if (mainMethod == null )
111+ throw new Exception ("No main method was found" );
112+
101113 mainMethod .setAccessible (true );
102- mainMethod .invoke (null , new Object [] { args });
114+ Parameter [] params = mainMethod .getParameters ();
115+
116+ if (params .length > 0 ) {
117+ if (params .length > 1 )
118+ throw new Exception ("No more than one arguments is accepted in main method" );
119+
120+ Parameter argParam = params [0 ];
121+ if (!String [].class .getCanonicalName ().equals (argParam .getType ().getCanonicalName ()))
122+ throw new Exception ("Argument of main method is not accepted" );
123+
124+ mainMethod .invoke (null , new Object [] { args });
125+ } else {
126+ mainMethod .invoke (null );
127+ }
103128 }
104129
105130 /**
You can’t perform that action at this time.
0 commit comments