嵌入式Jetty 8热部署类(使用Maven) [英] Embedded Jetty 8 hot deploy classes (using Maven)

查看:574
本文介绍了嵌入式Jetty 8热部署类(使用Maven)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了一个标准的Maven webapp结构,它使用Spring MVC。

I have a standard Maven webapp structure defined, and it uses Spring MVC.

我使用嵌入式Jetty服务器(java类)来测试开发中的应用程序。

I am using an embedded Jetty server (java class) for testing the application in development.

下面概述了用于创建Jetty服务器的代码。如果我对任何JSP文件进行更改,则浏览器中的更改立即

The code used to create the Jetty server is outlined below. If I make changes to any JSP files, the changes are immediately visible in the browser.

但是,如果我更改任何类文件,例如控制器,更改是不是热部署?

However if I change any class files, e.g Controllers, the changes are not hot deployed?

我该怎么办才能让它工作?

What do I have to do get this to work?

I已经搜索了这个,我想我需要使用类 org.eclipse.jetty.util.Scanner ,特别是 setScanInterval 方法,但不知道如何连接它?

I have searched this and I think I need to use the class org.eclipse.jetty.util.Scanner and specifically the setScanInterval method, but not sure how to wire this up?

以下是创建服务器的代码

Here is the code to create the Server

    String webAppDir = "src/main/webapp/";
    Server server = new Server(8080);
    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath("/");
    webApp.setDescriptor(webAppDir + "/WEB-INF/web.xml");
    webApp.setResourceBase(webAppDir);
    webApp.setParentLoaderPriority(true);

    HandlerCollection hc = new HandlerCollection();
    ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
    hc.setHandlers(new Handler[] { contextHandlerCollection });
    hc.addHandler(webApp);
    server.setHandler(hc);
    return server;

提前致谢

推荐答案

对于热部署,您需要使用WebAppProvider和DeploymentManager。您可以配置为管理扫描更改和重新加载webapp的那些。很明显,WebappContext不是管理webapp部署的,它只是部署的容器类,因此有另一种机制可以处理部署/重新部署的概念。

For hot deployment you need to use the WebAppProvider and the DeploymentManager. Those you can configure to manage the scanning for changes and the reloading of the webapp. So it is clear, the WebappContext is not what manages the deployment of a webapp, it is merely the container class that is gets deployed so there is another mechanism that works outside of that which can handle the concepts of deploy/redeploy.

http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-deploy/src/test /resources/jetty-deploy-wars.xml

您可以在那里获取xml块并转换为嵌入式执行此操作所需的java调用。

You can take that chunk of xml there and convert into the java calls you need to do this embedded.

或使用类似jrebel jvm插件的东西,它提供自动类重新加载。

Or use something like the jrebel jvm plugin which provides for automatic class reloading.

这篇关于嵌入式Jetty 8热部署类(使用Maven)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆