@@ -1130,6 +1130,34 @@ public static void runApp(@NonNull String[] args, @NonNull Consumer<Jooby> consu
11301130 runApp (args , ExecutionMode .DEFAULT , consumerProvider (consumer ));
11311131 }
11321132
1133+ /**
1134+ * Setup default environment, logging (logback or log4j2) and run application.
1135+ *
1136+ * @param args Application arguments.
1137+ * @param server Server to run.
1138+ * @param consumer Application consumer.
1139+ */
1140+ public static void runApp (
1141+ @ NonNull String [] args , @ NonNull Server server , @ NonNull Consumer <Jooby > consumer ) {
1142+ runApp (args , server , ExecutionMode .DEFAULT , consumer );
1143+ }
1144+
1145+ /**
1146+ * Setup default environment, logging (logback or log4j2) and run application.
1147+ *
1148+ * @param args Application arguments.
1149+ * @param server Server to run.
1150+ * @param consumer Application consumer.
1151+ */
1152+ public static void runApp (
1153+ @ NonNull String [] args ,
1154+ @ NonNull Server server ,
1155+ @ NonNull ExecutionMode executionMode ,
1156+ @ NonNull Consumer <Jooby > consumer ) {
1157+ configurePackage (consumer .getClass ().getPackage ());
1158+ runApp (args , server , executionMode , List .of (consumerProvider (consumer )));
1159+ }
1160+
11331161 /**
11341162 * Setup default environment, logging (logback or log4j2) and run application.
11351163 *
@@ -1208,37 +1236,38 @@ public static void runApp(
12081236 @ NonNull Server server ,
12091237 @ NonNull ExecutionMode executionMode ,
12101238 @ NonNull List <Supplier <Jooby >> provider ) {
1239+
12111240 /* Dump command line as system properties. */
12121241 parseArguments (args ).forEach (System ::setProperty );
12131242 var apps = new ArrayList <Jooby >();
12141243 var targetServer = server .getLoggerOff ().isEmpty () ? server : MutedServer .mute (server );
1215- for (var factory : provider ) {
1216- var app = createApp (server , executionMode , factory );
1217- /*
1218- When running a single app instance, there is no issue with server options, when multiple
1219- apps set options a warning will be printed
1220- */
1221- ServerOptions .from (app .getConfig ())
1222- .ifPresent (
1223- options -> {
1224- options .setServer (server .getName ());
1225- server .setOptions (options );
1226- });
1227- apps .add (app );
1228- }
12291244 try {
1245+ for (var factory : provider ) {
1246+ var app = createApp (server , executionMode , factory );
1247+ /*
1248+ When running a single app instance, there is no issue with server options, when multiple
1249+ apps set options a warning will be printed
1250+ */
1251+ ServerOptions .from (app .getConfig ())
1252+ .ifPresent (
1253+ options -> {
1254+ options .setServer (server .getName ());
1255+ server .setOptions (options );
1256+ });
1257+ apps .add (app );
1258+ }
1259+
12301260 targetServer .start (apps .toArray (new Jooby [0 ]));
12311261 } catch (Throwable startupError ) {
1232- apps .forEach (app -> app .stopped .set (true ));
12331262 try {
1234- server .stop ();
1263+ targetServer .stop ();
12351264 } catch (Throwable ignored ) {
12361265 // no need to log here
12371266 }
12381267 // rethrow
12391268 throw startupError instanceof StartupException
12401269 ? (StartupException ) startupError
1241- : new StartupException ("Startup resulted in exception" , startupError );
1270+ : new StartupException ("Application initialization resulted in exception" , startupError );
12421271 }
12431272 }
12441273
@@ -1268,13 +1297,6 @@ public static Jooby createApp(
12681297 Jooby .BOOT_SERVER = server ;
12691298 Jooby .BOOT_EXECUTION_MODE = executionMode ;
12701299 app = provider .get ();
1271- } catch (Throwable t ) {
1272- LoggerFactory .getLogger (Jooby .class )
1273- .error ("Application initialization resulted in exception" , t );
1274-
1275- throw t instanceof StartupException
1276- ? (StartupException ) t
1277- : new StartupException ("Application initialization resulted in exception" , t );
12781300 } finally {
12791301 Jooby .BOOT_EXECUTION_MODE = executionMode ;
12801302 Jooby .BOOT_SERVER = null ;
0 commit comments