1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
20 ******************************************************************************/
22 //========================================================================
23 //Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
24 //------------------------------------------------------------------------
25 //All rights reserved. This program and the accompanying materials
26 //are made available under the terms of the Eclipse Public License v1.0
27 //and Apache License v2.0 which accompanies this distribution.
29 // The Eclipse Public License is available at
30 // http://www.eclipse.org/legal/epl-v10.html
32 // The Apache License v2.0 is available at
33 // http://www.opensource.org/licenses/apache2.0.php
35 //You may elect to redistribute this code under either of these licenses.
36 //========================================================================
39 import org.eclipse.jetty.server.Handler;
40 import org.eclipse.jetty.server.Server;
41 import org.eclipse.jetty.server.handler.DefaultHandler;
42 import org.eclipse.jetty.server.handler.HandlerList;
43 import org.eclipse.jetty.server.handler.ResourceHandler;
45 public class JettyExamplesDir
49 * Simple Jetty FileServer. This is a simple example of Jetty configured as a
53 public static void main(String[] args) throws Exception
55 // Create a basic Jetty server object that will listen on port 8080. Note
56 // that if you set this to port 0
57 // then a randomly available port will be assigned that you can either look
58 // in the logs for the port,
59 // or programmatically obtain it for use in test cases.
60 Server server = new Server(8080);
62 // Create the ResourceHandler. It is the object that will actually handle
63 // the request for a given file. It is
64 // a Jetty Handler object so it is suitable for chaining with other handlers
65 // as you will see in other examples.
66 ResourceHandler resource_handler = new ResourceHandler();
67 // Configure the ResourceHandler. Setting the resource base indicates where
68 // the files should be served out of.
69 // In this example it is the current directory but it can be configured to
70 // anything that the jvm has access to.
71 resource_handler.setDirectoriesListed(true);
72 resource_handler.setWelcomeFiles(new String[] { "applets.html" });
73 resource_handler.setResourceBase(".");
75 // Add the ResourceHandler to the server.
76 // GzipHandler gzip = new GzipHandler();
77 // server.setHandler(gzip);
78 HandlerList handlers = new HandlerList();
79 handlers.setHandlers(new Handler[] { resource_handler,
80 new DefaultHandler() });
81 server.setHandler(handlers);
83 // Start things up! By using the server.join() the server thread will join
84 // with the current thread.
86 // "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()"