How to configure hot deploy in Eclipse

eclipse-luna

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.

eclipse-tomcat-hot-example1
eclipse-tomcat-hot-deploy-example2

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

eclipse-tomcat-hot-deploy-example3
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.

eclipse-hot-swap-failed

References

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

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
15 Comment threads
8 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
15 Comment authors
ashishSubhamRAJAT awasthiSiriMdhar Recent comment authors
newest oldest most voted
ashish
Guest
ashish

Thank a lot, doing this configuration has saved my time. But I am just wondering Isn’t the name in step 4 i.e. “Enable autoreloading enabled” opposite to what it is doing, since we have UNCHECKED this, then ideally we are telling do not enable autorealoading ?

Subham
Guest
Subham

Thank you. This saved me a lot of time, keep sharing java articles. Cheers!

RAJAT awasthi
Guest
RAJAT awasthi

USE DCEVM -The Dynamic Code Evolution Virtual Machine (DCE VM) is a modification of the Java HotSpot(TM) VM that allows unlimited redefinition of loaded classes at runtime. The current hotswapping mechanism of the HotSpot(TM) VM allows only changing method bodies. The enhanced VM allows adding and removing fields and methods as well as changes to the super types of a class.

Siri
Guest
Siri

How can i deploy an exploded war on tomcat using eclipse neon ide and still use the hot deploy option ? Not able to configure this , application doesn’t seem to be deployed on tomcat in eclipse ide

Mdhar
Guest
Mdhar

Thank you very much . I have wasted almost 4 hours by doing other changes.

JAC_JustAnotherCoder
Guest
JAC_JustAnotherCoder

Thank You . This saved my lot of time by letting me to avoid stop and start Tomcat :-)

trackback
Intellij IDEA – Auto reload a web application (hot deploy)

[…] How to configure hot deploy in Eclipse […]

Marcin
Guest
Marcin

Hot-deploy works quite well. But after that my spring context gets reloaded. Every bean of my app hast to be initiated and it takes lot of time. Is there a way to do a code change described in the article but WITHOUT spring context reload?

mkyong
Guest
mkyong

I believe Tomcat is auto restart, refer step 2.2, make sure Tomcat Plugin, “Auto Reload” is “Disabled“.

Niko
Guest
Niko

have done all the adjustments.
but tomcat starts always again? without clicking “continue”.
you have a clue?
thanks!

mkyong
Guest
mkyong

Refer step 2.2, make sure Tomcat Plugin, “Auto Reload” is “Disabled“.

Ted Gulesserian
Guest
Ted Gulesserian

I followed the directions, my Spring application keeps redeploying after I change anything. Not sure what I am doing wrong.

Ted Gulesserian
Guest
Ted Gulesserian

My resolution was to go with http://www.hotswapagent.org/ – It works well for me with my Spring war deployment.

Ted Gulesserian
Guest
Ted Gulesserian

Even with Hotswapagent my application kept reloading every time I modified a .java file when I had auto publish turned on, the fix was to do this in Tomcat’s context.xml file in addition to turning auto reloading off as described by mkyong above:


+

mkyong
Guest
mkyong

It is Tomcat restarted, refer step 2.2, make sure “Auto Reload” is disable..

Vladimir Dvorak
Guest
Vladimir Dvorak
Andreas Schwarz
Guest
Andreas Schwarz

Make a tutorial for configuring JRebel in Eclipse.

mkyong
Guest
mkyong

Sorry, I don’t have JRebel license.

Shiy
Guest
Shiy

Or just simply use JRebel?

Nemesis
Guest
Nemesis

JRebel is not free.

mkyong
Guest
mkyong

JRebel is good – http://zeroturnaround.com/software/jrebel/ , but I can’t afford the $300+/year license :)

Vladimir Dvorak
Guest
Vladimir Dvorak

For non-trivial class changes there is available a modification of HotSpot :
https://github.com/dcevm/dcevm
Together with HotswapAgent :
https://github.com/HotswapProjects/HotswapAgent
it can provide true hotswap not only for debugging!

Arto Nabito
Guest
Arto Nabito

Thanks for the tip, I was looking for the way to disable it, as it’s on by default for me. Quite a time consuming every save.