我正在开发一个Web应用程序,当我在Eclipse下开发时,我将Jetty作为开发和测试环境运行 .
当我对Java类进行更改时,Eclipse会自动将它们编译到构建目录,但是在我停止并启动服务器之前,Jetty不会看到更改 . 我知道Jetty支持使用ContextDeployer进行“热部署”,它将刷新更新的应用程序上下文,但它依赖于正在更新的上下文目录中的上下文文件 - 这在我的情况下并不是很有用 .
有没有办法设置Jetty,以便在更新它使用的任何类时重新加载Web应用程序?
我当前的jetty.xml看起来像这样:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Set name="ThreadPool"><!-- bla bla --></Set>
<Call name="addConnector"><!-- bla bla --></Call>
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="webapp" class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="displayName">My Web App</Set>
<Set name="resourceBase">src/main/webapp</Set>
<Set name="descriptor">src/main/webapp/WEB-INF/web.xml</Set>
<Set name="contextPath">/mywebapp</Set>
</New>
</Item>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
</Configure>
2 回答
我们还没有找到这样做的方法(除了实现我们自己的
org.eclipse.jetty.deploy.providers.WebAppProvider
版本) .我们已经将jetty配置为从webapps文件夹(WebappDeployer的属性
monitoredDirName
)热部署webapps .然后进行热部署,我将此文件夹中的链接重新创建到Eclipse项目的src / main / webapp文件夹中 . 链接必须加上后缀
.war
.不是真的自动但足够好并且避免Jetty重启 .
如果你继续重新实现WebappDeployer的路线,我就不会监视.class文件中的变化 - 它们在Eclipse编译时会发生太大的变化,特别是在自动构建的情况下 . 我将通过监视web.xml文件的更改来实现'Tomcat like'解决方案 . 然后,从Eclipse保存到此文件的虚拟更改将触发重新部署 .
也可以使用maven配置您的jetty应用程序并使用Jenkins开始定期构建(甚至每隔几秒钟,具体取决于您正在处理的机器)