01: package org.strecks.samples;
02:
03: import org.mortbay.jetty.Connector;
04: import org.mortbay.jetty.Handler;
05: import org.mortbay.jetty.Server;
06: import org.mortbay.jetty.handler.ContextHandlerCollection;
07: import org.mortbay.jetty.handler.DefaultHandler;
08: import org.mortbay.jetty.handler.HandlerCollection;
09: import org.mortbay.jetty.handler.RequestLogHandler;
10: import org.mortbay.jetty.nio.SelectChannelConnector;
11: import org.mortbay.jetty.webapp.WebAppContext;
12:
13: public class SampleStarter {
14:
15: public static void main(String[] args) {
16: try {
17: new SampleStarter().startServer();
18: } catch (Exception e) {
19: e.printStackTrace();
20: }
21: }
22:
23: public void startServer() throws Exception {
24: Server server = new Server();
25:
26: Connector connector = new SelectChannelConnector();
27: connector.setPort(8080);
28: server.setConnectors(new Connector[] { connector });
29:
30: HandlerCollection handlers = new HandlerCollection();
31: ContextHandlerCollection contexts = new ContextHandlerCollection();
32:
33: WebAppContext webAppContext1 = new WebAppContext(
34: "samples/actiontest/dist/actiontest", "/actiontest");
35: WebAppContext webAppContext2 = new WebAppContext(
36: "samples/holiday-booking/dist/holidaybooking",
37: "/holidaybooking");
38: contexts.addHandler(webAppContext1);
39: contexts.addHandler(webAppContext2);
40:
41: /*
42: This code is required for hot deployment, although
43: it needs to point to a valid jetty.xml file to work
44: correctly (ie it won't currently work)
45:
46: ContextDeployer contextDeployer = new ContextDeployer();
47: server.addLifeCycle(contextDeployer);
48:
49: contextDeployer.setContexts(contexts);
50: contextDeployer.setScanInterval(10);
51:
52: contexts.setServer(server);
53: */
54:
55: RequestLogHandler requestLogHandler = new RequestLogHandler();
56: handlers.setHandlers(new Handler[] { contexts,
57: new DefaultHandler(), requestLogHandler });
58: server.setHandler(handlers);
59:
60: server.setStopAtShutdown(true);
61: server.setSendServerVersion(true);
62:
63: server.start();
64: server.join();
65: }
66: }
|