@@ -410,7 +410,8 @@ private <T> T require(AttributeKey<T> key) {
410410 log .info (" app dir: {}" , System .getProperty ("user.dir" ));
411411 log .info (" tmp dir: {}" , tmpdir );
412412
413- log .info ("routes: \n \n {}\n \n listening on:\n http://localhost:{}{}\n " , router , server .getOptions ().getPort (),
413+ log .info ("routes: \n \n {}\n \n listening on:\n http://localhost:{}{}\n " , router ,
414+ server .getOptions ().getPort (),
414415 router .getContextPath ());
415416 return this ;
416417 }
@@ -429,6 +430,23 @@ private <T> T require(AttributeKey<T> key) {
429430 return router .toString ();
430431 }
431432
433+ public static void runApp (String [] args , @ Nonnull Class <? extends Jooby > applicationType ) {
434+ runApp (ExecutionMode .DEFAULT , args , applicationType );
435+ }
436+
437+ public static void runApp (ExecutionMode executionMode , String [] args ,
438+ @ Nonnull Class <? extends Jooby > applicationType ) {
439+ configurePackage (applicationType );
440+ runApp (executionMode , args , () ->
441+ (Jooby ) Stream .of (applicationType .getDeclaredConstructors ())
442+ .filter (it -> it .getParameterCount () == 0 )
443+ .findFirst ()
444+ .map (Throwing .throwingFunction (c -> c .newInstance ()))
445+ .orElseThrow (() -> new IllegalArgumentException (
446+ "Default constructor for: " + applicationType .getName ()))
447+ );
448+ }
449+
432450 public static void runApp (String [] args , @ Nonnull Supplier <Jooby > provider ) {
433451 runApp (ExecutionMode .DEFAULT , args , provider );
434452 }
@@ -465,7 +483,10 @@ public static void runApp(@Nonnull ExecutionMode mode, @Nonnull String[] args,
465483 }
466484
467485 private static void configurePackage (@ Nonnull Object provider ) {
468- Class providerClass = provider .getClass ();
486+ configurePackage (provider .getClass ());
487+ }
488+
489+ private static void configurePackage (@ Nonnull Class providerClass ) {
469490 if (!providerClass .getName ().contains ("KoobyKt" )) {
470491 System .setProperty (DEF_PCKG ,
471492 System .getProperty (DEF_PCKG , providerClass .getPackage ().getName ()));
0 commit comments