import java.util.Scanner; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; public class Main { public static void main(String[] args) { Server server = new Server(); ServerConnector connector = new ServerConnector(server); int port = 8080; if (args.length > 0) { try { port = Integer.parseInt(args[0]); } catch (Exception ex) {} } connector.setPort(port); server.addConnector(connector); String contextPath = "/MyServlet"; // Create a ServletContextHandler with contextPath. ServletContextHandler context = new ServletContextHandler(); context.setContextPath(contextPath); // サーブレットを追加する context.addServlet(MyDate.class, "/MyDate"); // サーブレットにパラメーターを設定する場合... // ServletHolder myDateHolder = context.addServlet(MyDate.class, "/MyDate"); // Configure the Servlet with init-parameters. // myDateHolder.setInitParameter("maxItems", "128"); context.addServlet(Aisatsu.class, "/Aisatsu"); // ... // Add the DefaultServlet to serve static content. ServletHolder servletHolder = context.addServlet(DefaultServlet.class, "/"); // Configure the DefaultServlet with init-parameters. servletHolder.setInitParameter("resourceBase", "src/main/webapp/"); servletHolder.setAsyncSupported(true); // Link the context to the server. server.setHandler(context); try { server.start(); System.err.printf("runs at:%n\thttp://locahost:%d%s/ServletName%n", port, contextPath); System.err.println("Hit enter to stop the server."); Scanner scanner = new Scanner(System.in); scanner.nextLine(); server.stop(); } catch (Exception ex) { ex.printStackTrace(); } } }