package ${package};

import java.io.IOException;

import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ${package}.guice.ApplicationModule;
import ${package}.jersey.GrizzlySetup;

import com.coreoz.plume.jersey.guice.JerseyGuiceFeature;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;

/**
 * The application entry point, where it all begins.
 */
public class WebApplication {

	private static final Logger logger = LoggerFactory.getLogger(WebApplication.class);

	public static void main(String[] args) throws IOException {
		long startTimestamp = System.currentTimeMillis();

		// initialize all application objects with Guice
		Injector injector = Guice.createInjector(Stage.PRODUCTION, new ApplicationModule());

		ResourceConfig jerseyResourceConfig = injector.getInstance(ResourceConfig.class);
		// enable Jersey to create objects through Guice Injector instance
		jerseyResourceConfig.register(new JerseyGuiceFeature(injector));
		// starts the server
		GrizzlySetup.start(
			jerseyResourceConfig,
			System.getProperty("http.port"),
			System.getProperty("http.address")
		);

		logger.info("Server started in {} ms", System.currentTimeMillis() - startTimestamp);
	}

}

@@ -631,16 +631,25 @@
 ption %7B%0A
+%09%09try %7B%0A%09
 %09%09long s
@@ -695,16 +695,17 @@
 s();%0A%0A%09%09
+%09
 // initi
@@ -745,16 +745,17 @@
 h Guice%0A
+%09
 %09%09Inject
@@ -836,16 +836,17 @@
 ());%0A%0A%09%09
+%09
 Resource
@@ -921,16 +921,17 @@
 ass);%0A%09%09
+%09
 // enabl
@@ -989,16 +989,17 @@
 nstance%0A
+%09
 %09%09jersey
@@ -1059,16 +1059,17 @@
 or));%0A%09%09
+%09
 // start
@@ -1081,16 +1081,17 @@
  server%0A
+%09
 %09%09Grizzl
@@ -1103,24 +1103,25 @@
 p.start(%0A%09%09%09
+%09
 jerseyResour
@@ -1130,16 +1130,17 @@
 Config,%0A
+%09
 %09%09%09Syste
@@ -1170,16 +1170,17 @@
 t%22),%0A%09%09%09
+%09
 System.g
@@ -1208,20 +1208,22 @@
 ess%22)%0A%09%09
+%09
 );%0A%0A
+%09
 %09%09logger
@@ -1301,14 +1301,426 @@
 stamp);%0A
+%09%09%7D catch (Exception e) %7B%0A%09%09%09logger.error(%22Failed to start the server%22, e);%0A%09%09%09// This line is important, because during initialization some libraries change the main thread type%0A%09%09%09// to daemon, which mean that even if the project is completely down, the JVM is not stopped.%0A%09%09%09// Stopping the JVM is important to enable production supervision tools to detect and restart the project.%0A%09%09%09System.exit(1);%0A%09%09%7D%0A%09%09%0A
 %09%7D%0A%0A%7D%0A

Make sure the JVM stops when an error happened during initialization