01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.quickstart;
06:
07: import org.mortbay.http.SocketListener;
08: import org.mortbay.jetty.Server;
09: import org.mortbay.jetty.servlet.WebApplicationContext;
10:
11: import java.util.List;
12: import java.util.Map;
13: import java.io.File;
14:
15: /**
16: * To start a Jetty server used by the QuickStart application.
17: */
18: public class JettyServer {
19: /**
20: * The system property name used to specify a directory of webapps.
21: */
22: public static final String WEBAPPS_DIR_PROPERTY = "webapps.dir";
23:
24: public static void startServer(int port, String context,
25: List pathPriority, Map paths, String resolver)
26: throws Exception {
27: try {
28: Server server = new Server();
29: SocketListener socketListener = new SocketListener();
30: socketListener.setPort(port);
31: server.addListener(socketListener);
32:
33: WebApplicationContext ctx;
34: if (resolver == null) {
35: ctx = new MultiWebApplicationContext(pathPriority,
36: paths);
37: } else {
38: ctx = new MultiWebApplicationContext(pathPriority,
39: paths, resolver);
40: }
41: ctx.setClassLoader(Thread.currentThread()
42: .getContextClassLoader());
43: ctx.setContextPath(context);
44: server.addContext(null, ctx);
45:
46: // Add in extra webapps dir (see WW-1319)
47: String webappsDir = System
48: .getProperty(WEBAPPS_DIR_PROPERTY);
49: if (webappsDir != null && new File(webappsDir).exists()) {
50: server.addWebApplications(webappsDir);
51: }
52:
53: server.start();
54: } catch (Exception e) {
55: e.printStackTrace();
56: }
57: }
58: }
|