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 //========================================================================
40 import org.eclipse.jetty.server.Handler;
41 import org.eclipse.jetty.server.Server;
42 import org.eclipse.jetty.server.handler.DefaultHandler;
43 import org.eclipse.jetty.server.handler.HandlerList;
44 import org.eclipse.jetty.server.handler.ResourceHandler;
46 public class JettyExamplesDir
50 * Simple Jetty FileServer. This is a simple example of Jetty configured as a
54 public static void main(String[] args) throws Exception
56 // Create a basic Jetty server object that will listen on port 8080. Note
57 // that if you set this to port 0
58 // then a randomly available port will be assigned that you can either look
59 // in the logs for the port,
60 // or programmatically obtain it for use in test cases.
61 Server server = new Server(8080);
63 // Create the ResourceHandler. It is the object that will actually handle
64 // the request for a given file. It is
65 // a Jetty Handler object so it is suitable for chaining with other handlers
66 // as you will see in other examples.
67 ResourceHandler resource_handler = new ResourceHandler();
68 // Configure the ResourceHandler. Setting the resource base indicates where
69 // the files should be served out of.
70 // In this example it is the current directory but it can be configured to
71 // anything that the jvm has access to.
72 resource_handler.setDirectoriesListed(true);
73 resource_handler.setWelcomeFiles(new String[]
75 resource_handler.setResourceBase(".");
77 // Add the ResourceHandler to the server.
78 // GzipHandler gzip = new GzipHandler();
79 // server.setHandler(gzip);
80 HandlerList handlers = new HandlerList();
81 handlers.setHandlers(new Handler[]
82 { resource_handler, new DefaultHandler() });
83 server.setHandler(handlers);
85 // Start things up! By using the server.join() the server thread will join
86 // with the current thread.
88 // "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()"