Tomcat和Eclipse Zero Turnaround部署 [英] Tomcat and Eclipse Zero Turnaround Deployment
问题描述
到目前为止,我有我的输出Eclipse将内置的类放在我的Web应用程序的 WEB-INF / classes
文件夹中。
我也有一个可重新上载的上下文,将 web.xml
作为被监视的资源。任何编辑/保存到此文件 重新加载我的网络应用程序,花费了一秒钟 - 比构建新的战争文件并全面部署它快得多。
但是,当我编辑任何源文件时,我想要做的是触发重新部署。由于Tomcat中的.class文件被修改,似乎我只需要监视 WEB-INF / classes
文件夹中的任何更改,它是孩子。
我已经读过,我可以在Tomcat的 context.xml
中添加其他观看资源,但这似乎不要相当我需要的 - 除非可以指定将被监视的目录(包括递归监视子文件夹和文件)?
<语境GT;
< WatchedResource> WEB-INF / web.xml< / WatchedResource>
< WatchedResource> WEB-INF / someother.file< / WatchedResource>
< Manager pathname =/>
< / Context>
所以本质上,我的问题是可以看整个课程文件夹(不包括每个 WatchedResource
在Tomcat中触发重新部署?
如果没有,我可以将Eclipse配置为 touch
web.xml文件,每当我在该项目中保存源文件?我正在Windows系统上开发。 :(
PS我对JRebel产品不感兴趣任何答案应该是一个 strong>解决方案。
更新
根据Tomcat 文档,类文件夹应该通过将上下文设置为可重新加载来监控:
如果您希望Catalina在/ WEB-INF中的
监视类,设置为true / classes /
和/ WEB-INF / lib进行更改,如果检测到更改,
会自动重新加载web
应用程序。
只有对web.xml的更改似乎触发了重新加载,这是一个错误,还是我的设置不正确?
另外,我已经阅读了关于为给定上下文设置 docBase
属性:
docBase =webapps / someExample
出现s接近我需要的,因为我可以在Eclipse中快速重新发布。我唯一的问题是我需要几个web应用程序/ servlet在同一个端口等同时运行在Tomcat中。
对于这些情况,我将eclipse构建输出设置为WEB-INF / classes,并且创建一个上下文文件,将docBase设置为项目中的webapp文件夹(WEB-INF的父级)。这是手动放置在conf / Catalina / localhost(假设server.xml的某些元素的默认配置)。最终的结果是tomcat最终从开发目录服务。所以,更改一个servlet或其他类,它更新到classes文件夹。如果项目结构如下:
src
| -main
| -webapp
| -images
| -js
| -WEB-INF
| -jsp
| -classes
然后上下文将如下:
<?xml version =1.0encoding =UTF-8?>
< Context path =/ pathoadable =true
docBase =< pathtoproject> / src / main / webapp/>
I want to be able to deploy code changes to Tomcat (near instantly), while I'm developing in Eclipse.
So far, I have my output from Eclipse placing the built classes in the WEB-INF/classes
folder of my web application.
I also have a reloadable context, with the web.xml
as a watched resource. Any edit / save to this file does reload my web app, taking just over one second - much quicker than building a new war file and deploying it in full.
However, what I'd like to do is trigger the redeploy when I edit any source file. As the .class files are being modified in Tomcat, it seems I just need to monitor any changes in the WEB-INF/classes
folder and it's children.
I've read that I can add additional watched resources in Tomcat's context.xml
but this doesn't seem to be quite what I need - unless it's possible to specify a directory that will be watched (including recursively monitoring sub folders and files)?
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/someother.file</WatchedResource>
<Manager pathname=""/>
</Context>
So essentially, my question is can I watch the entire classes folder (without including each WatchedResource
explicitly) to trigger a redeploy in Tomcat?
If not, can I configure Eclipse to touch
the web.xml file, whenever I save a source file in that project? I'm developing on a Windows system. :(
PS I'm not interested in the JRebel product. Any answer should be a free solution.
Update
According to the Tomcat documentation, the classes folder should be monitored by setting the context to reloadable:
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected.
Only changes to the web.xml seem to trigger a reload. Is this a bug or is my setup incorrect?
Also, I've read about setting the docBase
attribute for a given context:
docBase="webapps/someExample"
This appears to be close to what I need, as I could then republish in Eclipse quickly. My only problem is that I require several web apps / servlets to be running in Tomcat concurrently, on the same port etc.
For these cases I set the eclipse build output to WEB-INF/classes as you have done and create a context file with the docBase set to the webapp folder (parent of WEB-INF) in the project. This is manually placed in conf/Catalina/localhost (assuming default configs for some elements of server.xml). End result is tomcat ends up serving from the development directory. So, change a servlet or other class and it is updated to the classes folder. Save a jsp and it is immediately available.
If project structured like:
src
|-main
|-webapp
|-images
|-js
|-WEB-INF
|-jsp
|-classes
Then context would be like:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/path" reloadable="true"
docBase="<pathtoproject>/src/main/webapp" />
这篇关于Tomcat和Eclipse Zero Turnaround部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!