简体   繁体   English

码头监控器WAR文件并在更改时更新

[英]Jetty monitor WAR file and update when it changes

I have an embedded Jetty running with several different contexts, one of which is a WAR file. 我有一个运行有多个不同上下文的嵌入式Jetty,其中一个是WAR文件。 I want Jetty to redeploy the war file when it changes (probably because it was rebuilt by another process). 我希望Jetty在war文件更改时重新部署它(可能是因为它是由另一个进程重建的)。

My current configuration: 我当前的配置:

    ContextHandlerCollection handler = new ContextHandlerCollection();
    WebAppContext webAppContext = new WebAppContext("../../webapp/ROOT.war", "/");
    handler.setHandlers(new Handler[]{
            new WebAppContext("src/main/webapp", "/api"),
            webAppContext
    });

    Server server = new Server(8080);
    server.setHandler(handler);

How do I change it to watch and redeploy the war file ( ../../webapp/ROOT.war )? 如何更改它以观看和重新部署war文件( ../../webapp/ROOT.war )?

Don't use a WebAppContext directly. 不要直接使用WebAppContext

Use the DeploymentManager to find and deploy your webapps. 使用DeploymentManager查找和部署您的Web应用程序。

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    server.setHandler(contexts);

    DeploymentManager deployer = new DeploymentManager();
    deployer.setContexts(contexts);
    deployer.setContextAttribute(
            "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
            ".*/servlet-api-[^/]*\\.jar$");

    WebAppProvider webapp_provider = new WebAppProvider();
    // The directory to monitor for WAR + XML files
    webapp_provider.setMonitoredDirName("/opt/jetty/webapps");
    webapp_provider.setScanInterval(1); // how often to scan
    webapp_provider.setExtractWars(true);
    webapp_provider.setTempDir(new File("/opt/jetty/work"));

    deployer.addAppProvider(webapp_provider);
    server.addBean(deployer);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM