作者(zhang854429783) eclipse通过tomcat热部署web项目 淩亂°似流年 2022-07-17 01:43 167阅读 0赞 # [eclipse通过tomcat热部署web项目][eclipse_tomcat_web] # 标签: [eclipse][][hot-deploy][][tomcat][] 2015-11-28 20:29 246人阅读 [评论][Link 1](1) 收藏 [举报][Link 2] ![category_icon.jpg][] 分类: java(12) ![arrow_triangle_20_down.jpg][] eclipse(5) ![arrow_triangle_20_down.jpg][] tomcat 目录[(?)][Link 3][\[-\]][Link 3] 1. [怎么配置eclipse热部署][eclipse 1] 1. [热部署例子][Link 4] 1. [1 源代码][1] 2. [2 修改代码添加一些日志][2] 2. [在eclipse里面配置热部署][eclipse 2] 1. [1 单击Overview选项卡][1 _Overview] 1. [11 展开Server Options勾选Serve modules without publishing选项][11 _Server Options_Serve modules without publishing] 2. [12 展开publishing勾选Automatically publish when resources change选项这个配置是用来热部署资源如JSPXML和properties文件等][12 _publishing_Automatically publish when resources change_JSPXML_properties] 2. [2 单击Modules选项卡确保Auto Reload是被禁用的][2 _Modules_Auto Reload] 3. [4 以DEBUG模式启动tomcat热部署在DEBUG模式下才可用][4 _DEBUG_tomcat_DEBUG] 3. [限制][Link 5] # 怎么配置eclipse热部署 # 本文章将会演示怎么配置eclipse调试器在不重启服务器的情况下支持热部署,热插拔或者热码替换。 环境: * Eclipse 4.4(老版本也一样支持) * Eclipse Tomcat 插件 -------------------- ## 1. 热部署例子 ## 通过这个简单的热部署例子,可以在不用重启tomcat的情况下是代码修改生效。假设一个简单的Spring MVC Web项目已经通过eclipse部署到tomcat里。 ### 1.1 源代码 ### <code class="language-java hljs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Controller</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">class</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">TaskController</span> {</span> <span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@RequestMapping</span>(value = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/task"</span>, method = RequestMethod.GET) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> ModelAndView <span class="hljs-title" style="box-sizing: border-box;">index</span>() { logger.debug(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"index()"</span>); ModelAndView model = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> ModelAndView(); model.setViewName(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"index"</span>); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> model; } ......</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul> 访问 : [http://localhost:8080/project/task][http_localhost_8080_project_task] > //output > DEBUG c.m.o.web.controller.TaskController - index() ### 1.2 修改代码,添加一些日志 ### <code class="language-java hljs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Controllerpublic</span> class TaskController { <span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@RequestMapping</span>(value = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/task"</span>, method = RequestMethod.GET) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> ModelAndView <span class="hljs-title" style="box-sizing: border-box;">index</span>() { logger.debug(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"index() - NEW - NO RESTART"</span>); ModelAndView model = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> ModelAndView(); model.setViewName(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"index"</span>); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> model; } ......</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li></ul> 再次访问:[http://localhost:8080/project/task][http_localhost_8080_project_task] > //output > DEBUG c.m.o.web.controller.TaskController - index() - NEW - NO RESTART ## 2. 在eclipse里面配置热部署 ## 双击tomcat,打开tomcat的配置界面,按如下几个步骤配置eclipse热部署: ![这里写图片描述][20160729202227123] ### 2.1 单击“Overview”选项卡 ### #### 2.1.1 展开“Server Options”,勾选“Serve modules without publishing”选项 #### ![这里写图片描述][20160729201951322] #### 2.1.2 展开”publishing“,勾选”Automatically publish when resources change“选项。这个配置是用来热部署资源,如:JSP,XML和properties文件等。 #### ![双击tomcat][tomcat 1] ![勾选自动发布当资源改变时][20151128195152519] ### 2.2 单击”Modules“选项卡,确保”Auto Reload“是被禁用的 ### ![设置][20151128201200213] ### 2.4 以DEBUG模式启动tomcat,热部署在DEBUG模式下才可用 ### ## 3. 限制 ## 热部署只支持方法内代码的修改,如果添加了新的类或方法依然需要重启才能生效。 为了模拟这种情况,尝试添加了一个新方法,弹出了提示框,JVM不能热切换这个修改的代码。 ![替换失败][20151128202639137] 顶 1 踩 [eclipse_tomcat_web]: http://blog.csdn.net/zhang854429783/article/details/50086923 [eclipse]: http://www.csdn.net/tag/eclipse [hot-deploy]: http://www.csdn.net/tag/hot-deploy [tomcat]: http://www.csdn.net/tag/tomcat [Link 1]: http://blog.csdn.net/zhang854429783/article/details/50086923#comments [Link 2]: http://blog.csdn.net/zhang854429783/article/details/50086923#report [category_icon.jpg]: /images/20220717/ba493825aa77468286d317846dc45037.png [arrow_triangle_20_down.jpg]: /images/20220717/472094e4050c48d280b03b426e337cef.png [Link 3]: http://blog.csdn.net/zhang854429783/article/details/50086923# [eclipse 1]: http://blog.csdn.net/zhang854429783/article/details/50086923#t0 [Link 4]: http://blog.csdn.net/zhang854429783/article/details/50086923#t1 [1]: http://blog.csdn.net/zhang854429783/article/details/50086923#t2 [2]: http://blog.csdn.net/zhang854429783/article/details/50086923#t3 [eclipse 2]: http://blog.csdn.net/zhang854429783/article/details/50086923#t4 [1 _Overview]: http://blog.csdn.net/zhang854429783/article/details/50086923#t5 [11 _Server Options_Serve modules without publishing]: http://blog.csdn.net/zhang854429783/article/details/50086923#t6 [12 _publishing_Automatically publish when resources change_JSPXML_properties]: http://blog.csdn.net/zhang854429783/article/details/50086923#t7 [2 _Modules_Auto Reload]: http://blog.csdn.net/zhang854429783/article/details/50086923#t8 [4 _DEBUG_tomcat_DEBUG]: http://blog.csdn.net/zhang854429783/article/details/50086923#t9 [Link 5]: http://blog.csdn.net/zhang854429783/article/details/50086923#t10 [http_localhost_8080_project_task]: http://localhost:8080/project/task [20160729202227123]: /images/20220717/a77c6494719b460e95fde4f3cc064d7f.png [20160729201951322]: /images/20220717/944f612c91754a44a41646e7a01610c9.png [tomcat 1]: /images/20220717/7ebf07ff9ddb4db6abf854497e515c8e.png [20151128195152519]: /images/20220717/bfc84773f1834faba92983445735142b.png [20151128201200213]: /images/20220717/abec01aac3be4353ac6f90796e26aa4d.png [20151128202639137]: /images/20220717/8955bd89e1eb42e5981166ab6570a0da.png
还没有评论,来说两句吧...