当更改类时,如何配置Jetty来重新加载WebAppContext [英] How to configure Jetty to reload a WebAppContext when classes are changed
问题描述
当我对Java类进行更改时,Eclipse正在开发一个Web应用程序,并且我在开发和测试环境中运行Jetty。自动将其编译为构建目录,但是在停止并启动服务器之前,Jetty将无法看到更改。我知道Jetty支持使用ContextDeployer的热部署,这将刷新更新的应用程序上下文,但它依赖于正在更新的上下文目录中的上下文文件 - 这在我的情况下不是很有用。
有没有办法设置Jetty,以便在使用任何类的更新时重新加载网络应用程序?
我目前的码头.xml看起来像这样:
<?xml version =1.0?>
<!DOCTYPE配置PUBLIC - // Jetty //配置// ENhttp://www.eclipse.org/jetty/configure.dtd\">
<配置id =服务器class =org.eclipse.jetty.server.Server>
< Set name =ThreadPool><! - bla bla - >< / Set>
< Call name =addConnector><! - bla bla - >< / Call>
< Set name =handler>
< New id =Handlersclass =org.eclipse.jetty.server.handler.HandlerCollection>
< Set name =handlers>
< Array type =org.eclipse.jetty.server.Handler>
< Item>
<新建id =webappclass =org.eclipse.jetty.webapp.WebAppContext>
< Set name =displayName>我的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 =DefaultHandlerclass =org.eclipse.jetty.server.handler.DefaultHandler/>
< / Item>
< / Array>
< / Set>
< / New>
< / Set>
< / Configure>
我们还没有找到一种方法从实现我们自己的版本的 org.eclipse.jetty.deploy.providers.WebAppProvider
)。
我们有配置的jetty可以从Webapps文件夹(属性 monitoredDirName
)Web AppDeployer中部署webapps。
然后进行热部署,我将此文件夹中的链接重新创建到Eclipse项目的src / main / webapp文件夹。链接必须后缀为 .war
。
不是真的自动但足够好,避免Jetty重新启动。 p>
如果你去重新实现WebappDeployer的路由,我不会监视.class文件中的更改 - 它们在Eclipse编译时变化太大,特别是在自动构建。我将通过监视web.xml文件的更改来实现Tomcat like解决方案。然后,从Eclipse中保存到此文件的虚拟更改将触发重新部署。
I'm developing a web application and I run Jetty as the development and testing environment when I develop under Eclipse.
When I make changes to Java classes, Eclipse automatically compiles them to the build directory, but Jetty won't see the changes until I stop and start the server. I know that Jetty supports "hot deployment" using ContextDeployer that will refresh updated application contexts, but it relies on a context file in a context directory being updated - which is not very useful in my case.
Is there a way to set up Jetty so that it will reload the web app when any of the classes it uses is updated?
My current jetty.xml looks something like this:
<?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>
We have not found a way of doing this (aside from implementing our own version of the org.eclipse.jetty.deploy.providers.WebAppProvider
).
We have configured jetty to hot deploy webapps from the webapps folder (property monitoredDirName
of the WebappDeployer).
Then to hot deploy, I recreate my link in this folder to the src/main/webapp folder of my Eclipse project. The linked must be suffixed .war
.
Not really automatic but good enough and avoids a Jetty restart.
If you go the route of re-implementing a WebappDeployer, I would not monitor the changes in .class files - they change too much when compiled by Eclipse, particularly in the case of automatic builds. I would implement a 'Tomcat like' solution by monitoring changes to the web.xml file. Then a dummy change saved to this file from Eclipse would trigger a redeployment.
这篇关于当更改类时,如何配置Jetty来重新加载WebAppContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!