KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > web > JettyServer


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.web;
18
19 import org.mortbay.jetty.bio.SocketConnector;
20 import org.mortbay.jetty.webapp.WebAppContext;
21 import org.mortbay.jetty.Connector;
22 import org.mortbay.jetty.Handler;
23 import org.mortbay.jetty.Server;
24
25 /**
26  * A simple bootstrap class for starting Jetty in your IDE using the local web application.
27  *
28  * @version $Revision: 356269 $
29  */

30 public class JettyServer {
31
32     public static final int PORT = 8080;
33
34     public static final String JavaDoc WEBAPP_DIR = "src/webapp";
35
36     public static final String JavaDoc WEBAPP_CTX = "/";
37
38     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
39         int port = PORT;
40         if (args.length > 0) {
41             String JavaDoc text = args[0];
42             port = Integer.parseInt(text);
43         }
44         System.out.println("Starting Web Server on port: " + port);
45         Server server = new Server();
46         SocketConnector connector = new SocketConnector();
47         connector.setPort(port);
48         WebAppContext webapp = new WebAppContext();
49         webapp.setContextPath(WEBAPP_CTX);
50         webapp.setResourceBase(WEBAPP_DIR);
51         server.setHandlers(new Handler[] { webapp });
52         server.setConnectors(new Connector[] { connector });
53         server.start();
54     }
55 }
56
Popular Tags