View Javadoc

1   // ========================================================================
2   // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.embedded;
15  
16  import org.eclipse.jetty.server.Connector;
17  import org.eclipse.jetty.server.Server;
18  import org.eclipse.jetty.server.nio.SelectChannelConnector;
19  import org.eclipse.jetty.webapp.WebAppContext;
20  
21  public class OneWebApp
22  {
23      public static void main(String[] args) throws Exception
24      {
25          Server server = new Server();
26  
27          Connector connector = new SelectChannelConnector();
28          connector.setPort(Integer.getInteger("jetty.port",8080).intValue());
29          server.setConnectors(new Connector[]
30          { connector });
31  
32  
33          //If you're running this from inside Eclipse, then Server.getVersion will not provide
34          //the correct number as there is no manifest. Use the command line instead to provide the path to the
35          //test webapp
36          String war = args.length > 0?args[0]: "../test-jetty-webapp/target/test-jetty-webapp-"+Server.getVersion();
37          String path = args.length > 1?args[1]:"/";
38  
39          System.err.println(war + " " + path);
40  
41          WebAppContext webapp = new WebAppContext();
42          webapp.setContextPath(path);
43          webapp.setWar(war);
44          
45          //If the webapp contains security constraints, you will need to configure a LoginService
46          if (war.contains("test-jetty-webapp"))
47          {
48              org.eclipse.jetty.security.HashLoginService loginService = new org.eclipse.jetty.security.HashLoginService();
49              loginService.setName("Test Realm");
50              loginService.setConfig("src/test/resources/realm.properties");
51              webapp.getSecurityHandler().setLoginService(loginService);
52          }
53  
54          server.setHandler(webapp);
55  
56          server.start();
57          server.join();
58      }
59  }