Main class for running with an embedded jetty
[ical-validator.git] / src / main / java / net / bzzt / ical / Main.java
blob8bae12a325b4fa71e8edd787a291e94dcca6c30a
1 package net.bzzt.ical;
4 import org.mortbay.jetty.Server;
5 import org.mortbay.jetty.webapp.WebAppContext;
7 /**
8 *
9 * This class launches the web application in an embedded Jetty container.
10 * This is the entry point to your application. The Java command that is used for
11 * launching should fire this main method.
14 public class Main {
16 /**
17 * @param args
19 public static void main(String[] args) throws Exception{
20 String webappDirLocation = "src/main/webapp/";
22 //The port that we should run on can be set into an environment variable
23 //Look for that variable and default to 8080 if it isn't there.
24 String webPort = System.getenv("PORT");
25 if(webPort == null || webPort.isEmpty()) {
26 webPort = "8080";
29 Server server = new Server(Integer.valueOf(webPort));
30 WebAppContext root = new WebAppContext();
32 root.setContextPath("/");
33 root.setDescriptor(webappDirLocation+"/WEB-INF/web.xml");
34 root.setResourceBase(webappDirLocation);
36 //Parent loader priority is a class loader setting that Jetty accepts.
37 //By default Jetty will behave like most web containers in that it will
38 //allow your application to replace non-server libraries that are part of the
39 //container. Setting parent loader priority to true changes this behavior.
40 //Read more here: http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading
41 root.setParentLoaderPriority(true);
43 server.setHandler(root);
45 server.start();
46 server.join();