private void doStart() { if (!available(port)) throw new IllegalStateException("port: " + port + " already in use!"); deleteSessionData(); System.out.println("Starting JFinal " + Const.JFINAL_VERSION); server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); server.addConnector(connector); webApp = new WebAppContext(); webApp.setThrowUnavailableOnStartupException(true); // 在启动过程中允许抛出异常终止启动并退出 JVM webApp.setContextPath(context); webApp.setResourceBase(webAppDir); // webApp.setWar(webAppDir); webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); webApp.setInitParameter( "org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); // webApp.setInitParams(Collections.singletonMap("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false")); persistSession(webApp); server.setHandler(webApp); changeClassLoader(webApp); // configureScanner if (scanIntervalSeconds > 0) { Scanner scanner = new Scanner(PathKit.getRootClassPath(), scanIntervalSeconds) { public void onChange() { try { System.err.println("\nLoading changes ......"); webApp.stop(); JFinalClassLoader loader = new JFinalClassLoader(webApp, getClassPath()); webApp.setClassLoader(loader); webApp.start(); System.err.println("Loading complete."); } catch (Exception e) { System.err.println( "Error reconfiguring/restarting webapp after change in watched files"); LogKit.error(e.getMessage(), e); } } }; System.out.println("Starting scanner at interval of " + scanIntervalSeconds + " seconds."); scanner.start(); } try { System.out.println("Starting web server on port: " + port); server.start(); System.out.println("Starting Complete. Welcome To The JFinal World :)"); server.join(); } catch (Exception e) { LogKit.error(e.getMessage(), e); System.exit(100); } return; }
@Override protected Server createServer() { Server server = new Server( new Integer(ConfigContext.getCurrentContextConfig().getProperty("ksb.client2.port"))); URL webRoot = getClass().getClassLoader().getResource(WEB_ROOT); String location = webRoot.getPath(); LOG.debug("#####################################"); LOG.debug("#"); LOG.debug("# Starting Client2 using web root " + location); LOG.debug("#"); LOG.debug("#####################################"); WebAppContext context = new WebAppContext(location, CONTEXT); context.setThrowUnavailableOnStartupException(true); context.setClassLoader(new KsbTestClientClassLoader()); server.setHandler(context); return server; }