//Add DefaultHandler Handler[] handlers = new Handler[handlers1.length + 1]; System.arraycopy(handlers1, 0, handlers, 0, handlers1.length); handlers[handlers.length - 1] = new DefaultHandler();
HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.setHandlers(handlers); server.setHandler(handlerCollection);
server.start(); }
System.out.printf("Server started in %.3f seconds. %n", ((double) (System.currentTimeMillis() - startTime)) / 1000); }
static void deployWebApp(String war, String contextPath, int port) throws Exception { Server server = portServers.get(port);
//1) Set Connector/port if (server == null) { server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); server.setConnectors(new Connector[] { connector });
portServers.put(port, server); }
//2) Set Context 'Context Path' and 'War' WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath(contextPath); //It can be war file's path or webapp directory webAppContext.setWar(war);
List<WebAppContext> webAppContexts = webAppContextLists.get(port); if (webAppContexts == null) { webAppContexts = new ArrayList<WebAppContext>(); webAppContextLists.put(port, webAppContexts); } webAppContexts.add(webAppContext);
System.out.printf("[%s] is ready...%n", contextPath); } }