嵌入式Jetty 8热部署类(使用Maven)

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

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

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

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

我该怎么办才能让它发挥作用?

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

以下是创建服务器的代码

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部署的,它只是部署的容器类,因此有另一种机制可以在可以处理部署/重新部署的概念之外工作。

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

你可以把那个xml块转换成你需要嵌入的java调用。

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