gpt4 book ai didi

java - 更改类时如何配置 Jetty 以重新加载 WebAppContext

转载 作者:行者123 更新时间:2023-12-04 05:53:43 25 4
gpt4 key购买 nike

我正在开发一个 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>

最佳答案

我们还没有找到这样做的方法(除了实现我们自己版本的 org.eclipse.jetty.deploy.providers.WebAppProvider )。

我们已将 jetty 配置为从 webapps 文件夹(WebappDeployer 的属性 monitoredDirName)热部署 webapp。

然后为了热部署,我在这个文件夹中重新创建了指向我的 Eclipse 项目的 src/main/webapp 文件夹的链接。链接必须后缀.war .

不是真正自动但足够好并且避免了 jetty 重启。

如果您采用重新实现 WebappDeployer 的方法,我将不会监视 .class 文件中的更改 - 它们在由 Eclipse 编译时更改太多,尤其是在自动构建的情况下。我将通过监视对 web.xml 文件的更改来实现“类似 Tomcat”的解决方案。然后从 Eclipse 保存到该文件的虚拟更改将触发重新部署。

关于java - 更改类时如何配置 Jetty 以重新加载 WebAppContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9767464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com