How to configure hot deploy in Eclipse

摘要: In this tutorial, we will show you how to configure Eclipse debugger to support hot deploy, hot swap or hot code replace without restarting the Server, this speed development a lot.

In this tutorial, we will show you how to configure Eclipse debugger to support hot deploy, hot swap or hot code replace without restarting the Server, this speed development a lot.

Environment :

  1. Eclipse 4.4 (Supported in older version as well)
  2. Eclipse Tomcat Plugin

1. Hot deploy example

Review a simple hot deploy example, code changes without restarting the Tomcat plugin. Assume a simple Spring MVC web project is deployed via the Eclipse-Tomcat plugin :

1.1 Original code

TaskController.class
@Controller
public class TaskController {
	@RequestMapping(value = "/task", method = RequestMethod.GET)
	public ModelAndView index() {
		logger.debug("index()");
		ModelAndView model = new ModelAndView();
		model.setViewName("index");
		return model;

Access : http://localhost:8080/project/task

//output
DEBUG c.m.o.web.controller.TaskController - index()

1.2 Change the code, logs something else

TaskController.class
@Controller
public class TaskController {
	@RequestMapping(value = "/task", method = RequestMethod.GET)
	public ModelAndView index() {
		logger.debug("index() - NEW - NO RESTART");
		ModelAndView model = new ModelAndView();
		model.setViewName("index");
		return model;

Access again : http://localhost:8080/project/task

//output
DEBUG c.m.o.web.controller.TaskController - index() - NEW - NO RESTART

2. Configure Hot deploy in Eclipse

Some steps are required to make Eclipse supports hot deploy.

2.1 Double clicks on the Tomcat plugin, refer to publishing tab, make sure Automatically publish when resources change is selected. This should be the default option, to support “hot deploy” resources, for example : JSP, XML and properties files.

2.2 In the Tomcat Plugin page, clicks on the Module view, make sure Auto Reload is Disabled. Default is enabled.

Note
This is an important step, failed to set the auto reload to disabled, the Tomcat server will be restarted every time you modified something!

2.3 Start Project in DEBUG mode. Hot Deploy is supported in DEBUG mode only.

Done.

3. Limitation

Hot deploy has supported the code changes in the method implementation only. If you add a new class or a new method, restart is still required.

To simulate it, try to add a new method, following pop up screen will be displayed, saying the code changes cannot be hot swapped in the JVM.

References

  1. Intellij IDEA – Auto reload a web application (hot deploy)
  2. FAQ What is hot code replace?

上一篇: Gradle Spring 4 MVC Hello World Example
下一篇: Gradle Create a Jar file with dependencies
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号