當前位置: 首頁>>代碼示例>>Java>>正文


Java Server.setStopAtShutdown方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.server.Server.setStopAtShutdown方法的典型用法代碼示例。如果您正苦於以下問題:Java Server.setStopAtShutdown方法的具體用法?Java Server.setStopAtShutdown怎麽用?Java Server.setStopAtShutdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.server.Server的用法示例。


在下文中一共展示了Server.setStopAtShutdown方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static void startServer(String[] args) throws Exception {
	Server server = new Server(8080);
	
	WebAppContext ctx = new WebAppContext();
	ctx.setContextPath("/");
	ctx.setWar("src/main/webapp/");
	HandlerCollection hc = new HandlerCollection();
	hc.setHandlers(new Handler[] {ctx});
	
	server.setHandler(hc);
	server.setStopAtShutdown(true);
	server.start();
	
	server.join();
	
	// server.removeBean(o);
	// server.addBean(o);
}
 
開發者ID:ForJ-Latech,項目名稱:fwm,代碼行數:19,代碼來源:ScratchPad.java

示例2: main

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	Runtime.getRuntime().addShutdownHook(new ShutdownHook());

	Initiator.init();

	Server server = new Server(PORT);
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath(CONTEXT_PATH);
	server.setHandler(context);
	server.setStopAtShutdown(true);

	context.addServlet(new ServletHolder(new GetAllLang()), "/get_all_lang");
	context.addServlet(new ServletHolder(new Compile()), "/compile");
	context.addServlet(new ServletHolder(new Run()), "/run");
	server.join();
	server.start();

	LOGGER.info("Avalon-Executive server is now running at http://127.0.0.1:" + PORT + CONTEXT_PATH);
}
 
開發者ID:ProgramLeague,項目名稱:Avalon-Executive,代碼行數:20,代碼來源:MainServer.java

示例3: createJettyServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static Server createJettyServer(int port, String contextPath) {

        Server server = new Server(port);
        server.setStopAtShutdown(true);

        ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain();
        URL location = protectionDomain.getCodeSource().getLocation();
        String warFile = location.toExternalForm();

        WebAppContext context = new WebAppContext(warFile, contextPath);
        context.setServer(server);

        // 設置work dir,war包將解壓到該目錄,jsp編譯後的文件也將放入其中。
        String currentDir = new File(location.getPath()).getParent();
        File workDir = new File(currentDir, "work");
        context.setTempDirectory(workDir);

        server.setHandler(context);
        return server;

    }
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:22,代碼來源:Launcher.java

示例4: createDevServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static Server createDevServer(int port, String contextPath) {

        Server server = new Server();
        server.setStopAtShutdown(true);

        ServerConnector connector = new ServerConnector(server);
        // 設置服務端口
        connector.setPort(port);
        connector.setReuseAddress(false);
        server.setConnectors(new Connector[] {connector});

        // 設置web資源根路徑以及訪問web的根路徑
        WebAppContext webAppCtx = new WebAppContext(DEFAULT_APP_CONTEXT_PATH, contextPath);
        webAppCtx.setDescriptor(DEFAULT_APP_CONTEXT_PATH + "/WEB-INF/web.xml");
        webAppCtx.setResourceBase(DEFAULT_APP_CONTEXT_PATH);
        webAppCtx.setClassLoader(Thread.currentThread().getContextClassLoader());
        server.setHandler(webAppCtx);

        return server;
    }
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:21,代碼來源:Launcher.java

示例5: main

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static void main(@NotNull @NonNls String[] args) throws Exception {
	PropertyConfigurator.configure(System.getProperty("user.dir") + "/log4j.properties");
	logger.warn("StrictFP | Back-end");
	logger.info("StrictFP Back-end is now running...");
	Server server = new Server(Constant.SERVER.SERVER_PORT);
	ServletContextHandler context =
			new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath("/api/v0");
	server.setHandler(context);
	server.setStopAtShutdown(true);
	// 像下麵這行一樣
	context.addServlet(new ServletHolder(new GetQuiz()), "/misc/getquiz");
	context.addServlet(new ServletHolder(new TimeLine()), "/timeline");
	context.addServlet(new ServletHolder(new Counter()), "/misc/counter");
	context.addServlet(new ServletHolder(new User()), "/user");
	context.addServlet(new ServletHolder(new Heartbeat()), "/misc/heartbeat");
	context.addServlet(new ServletHolder(new SafeCheck()), "/misc/safecheck");
	context.addServlet(new ServletHolder(new CheckCert()), "/auth/check_cert");
	//
	server.start();
	server.join();
}
 
開發者ID:ProgramLeague,項目名稱:strictfp-back-end,代碼行數:23,代碼來源:MainServer.java

示例6: createServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
 * 創建用於開發運行調試的JettyServer
 * @param port        訪問服務器的端口
 * @param contextPath 訪問服務器的地址
 * @param webAppPath  Web應用的目錄(需指向到WebRoot目錄下)
 */
private static Server createServer(int port, String contextPath, String webAppPath){
	Server server = new Server();
	//設置在JVM退出時關閉Jetty的鉤子
	//這樣就可以在整個功能測試時啟動一次Jetty,然後讓它在JVM退出時自動關閉
	server.setStopAtShutdown(true);
	//ServerConnector connector = new ServerConnector(server);
	SelectChannelConnector connector = new SelectChannelConnector();
	connector.setPort(port);
	//解決Windows下重複啟動Jetty不報告端口衝突的問題
	//在Windows下有個Windows + Sun的connector實現的問題,reuseAddress=true時重複啟動同一個端口的Jetty不會報錯
	//所以必須設為false,代價是若上次退出不幹淨(比如有TIME_WAIT),會導致新的Jetty不能啟動,但權衡之下還是應該設為False
	connector.setReuseAddress(false);
	server.setConnectors(new Connector[]{connector});
	//為了設置reuseAddress=false所以創建Connector,否則直接new Server(port)即可,通過查看Server源碼發現,二者是等效的
	//不過使用Connector的好處是可以讓Jetty監聽多個端口,此時創建多個綁定不同端口的Connector即可,最後一起setConnectors
	//Server server = new Server(port);
	//server.setStopAtShutdown(true);
	WebAppContext context = new WebAppContext(webAppPath, contextPath);
	//解決Windows環境下Lock靜態文件的問題
	//Jetty運行時會鎖住js、css等文件,導致不能修改保存,解決辦法是修改webdefault.xml中的useFileMappedBuffer=false
	//這裏試了很多遍都沒成功,後來注釋掉這裏的setDefaultsDescriptor(),也刪除項目中的webdefault-windows.xml
	//再重啟應用,竟然可以修改保存了,後來又反複重啟又試了幾次竟然都可以修改保存,很是奇怪
	//context.setDefaultsDescriptor("F:/Tool/Code/JavaSE/MyJettyDemo/test/webdefault-windows.xml");
	server.setHandler(context);
	return server;
}
 
開發者ID:v5java,項目名稱:demo-cas-server-web,代碼行數:33,代碼來源:JettyBootStrap.java

示例7: createServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
@SuppressWarnings("ConstantConditions")
private static Server createServer(){
	Server server = new Server();
	server.setStopAtShutdown(true);
	SelectChannelConnector connector = new SelectChannelConnector();
	connector.setPort(port);
	connector.setReuseAddress(false);
	server.setConnectors(new Connector[]{connector});
	String webAppPath = JettyBootStrap.class.getClassLoader().getResource(".").getFile();
	webAppPath = webAppPath.substring(0, webAppPath.indexOf("target")) + "src/main/webapp";
	WebAppContext context = new WebAppContext(webAppPath, contextPath);
	server.setHandler(context);
	return server;
}
 
開發者ID:v5java,項目名稱:demo-springmvc-shiro,代碼行數:15,代碼來源:JettyBootStrap.java

示例8: startServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
 * Method for starting the Jetty server with the ATS Agent webapp.
 * @param port the port on which to start the server.
 * @return the started server.
 * @throws IOException
 */
private static Server startServer() throws IOException {

    addAppender();

    final int agentPort = getAgentDefaultPort();
    log.info("Starting ATS agent at port: " + agentPort);

    final String jettyHome = getJettyHome();

    logSystemInformation(jettyHome);

    // start the server
    Connector connector = new SelectChannelConnector();
    connector.setPort(agentPort);

    Server server = new Server();
    server.setConnectors(new Connector[]{ connector });

    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath("/agentapp");
    webApp.setWar(jettyHome + "/webapp/agentapp.war");

    server.setHandler(webApp);
    server.setStopAtShutdown(true);

    setExtraClasspath(webApp, jettyHome);

    try {
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    log.info("ATS agent started");
    return server;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:44,代碼來源:ContainerStarter.java

示例9: createGitServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
private Server createGitServer(int port) throws Exception {
    final Server server = new Server(port);

    final ServletHandler handler = new ServletHandler();
    server.setHandler(handler);
    handler.addServletWithMapping(new ServletHolder(createGitServlet()), "/*");

    server.start();
    server.setStopAtShutdown(true);

    LOGGER.info("Started serving local git repositories [" + this.repositories.values().stream().map(
        LazilyLoadedRepository::getName).collect(Collectors.toList()) + "] under http://localhost:" + port);
    return server;
}
 
開發者ID:arquillian,項目名稱:smart-testing,代碼行數:15,代碼來源:EmbeddedHttpGitServer.java

示例10: createAndStartServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static Server createAndStartServer(int port, Map<Class<? extends Servlet>, String> handlers) throws Exception {
    Server server = new Server(port);
    server.setStopAtShutdown(true);
    ServletHandler sh = new ServletHandler();
    handlers.entrySet().forEach(e -> sh.addServletWithMapping(e.getKey(), e.getValue()));
    server.setHandler(sh);
    server.start();
    return server;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:10,代碼來源:RemoteServerHelper.java

示例11: startServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
@BeforeClass
public static void startServer() throws Exception {
    Server server = new Server(31245);
    server.setStopAtShutdown(true);
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(CourseInfoServlet.class, "/courseUnitInfo");
    handler.addServletWithMapping(CourseInfoServlet.class, "/courseUnitInfo/oulu");
    server.setHandler(handler);
    server.start();
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:11,代碼來源:CourseInfoImportTest.java

示例12: start

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public void start(boolean devMode, int port) throws Exception {

        Server server = new Server(new QueuedThreadPool(500));

        WebAppContext appContext = new WebAppContext();

        String resourceBasePath = "";
        //開發者模式
        if (devMode) {
            String artifact = MavenUtils.get(Thread.currentThread().getContextClassLoader()).getArtifactId();
            resourceBasePath = artifact + "/src/main/webapp";
        }
        appContext.setDescriptor(resourceBasePath + "WEB-INF/web.xml");
        appContext.setResourceBase(resourceBasePath);
        appContext.setExtractWAR(true);

        //init param
        appContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        if (CommonUtils.isWindowOs()) {
            appContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
        }

        //for jsp support
        appContext.addBean(new JettyJspParser(appContext));
        appContext.addServlet(JettyJspServlet.class, "*.jsp");

        appContext.setContextPath("/");
        appContext.getServletContext().setExtendedListenerTypes(true);
        appContext.setParentLoaderPriority(true);
        appContext.setThrowUnavailableOnStartupException(true);
        appContext.setConfigurationDiscovered(true);
        appContext.setClassLoader(Thread.currentThread().getContextClassLoader());

        ServerConnector connector = new ServerConnector(server);
        connector.setHost("0.0.0.0");
        connector.setPort(port);
        server.setConnectors(new Connector[]{connector});
        server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1024 * 1024 * 1024);
        server.setDumpAfterStart(false);
        server.setDumpBeforeStop(false);
        server.setStopAtShutdown(true);
        server.setHandler(appContext);
        logger.info("[opencron] JettyLauncher starting...");
        server.start();
    }
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:46,代碼來源:JettyLauncher.java


注:本文中的org.eclipse.jetty.server.Server.setStopAtShutdown方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。