private static final int PORT = 8080;
private static final int MAX_THREADS = 5;
public static void main(String[] args) throws Exception {
// This object will create our webapp's configuration for us
WebAppConfigurationBuilder configBuilder = new WebAppConfigurationBuilder();
// register our servlet to respond to the "/bar" pattern
configBuilder.addFilter(GuiceFilter.class, "/*");
configBuilder.addServlet(BasicServlet.class, "/bar");
// we need to be able to return a directory
// when javax.servlet.ServletContext.getRealPath("/") is called
// hence the need for a context directory
File contextDir = new File(System.getProperty("java.io.tmpdir"));
// We want "" to be returned by
// javax.servlet.http.HttpServletRequest.getContextPath() (ie. the root context)
// so we use the "ROOT" context name (this is so we can have files called ROOT.war and not
// "".war
String context = "ROOT";
// create a collection of webapps that just contains a single webapp
WebAppCollection webapps
= WebAppCollectionFactory.createWebAppCollectionWithOneContext(contextDir,
context, configBuilder.getConfiguration());
// start all of the webapps
webapps.startAll();
// create servlet engine configuration object
ServletEngineConfiguration config
= ServletEngineConfigurationImpl.create(PORT, MAX_THREADS);