14 Jan 2012

Hot Code Replace in Eclipse, or how to boost the debugging process

Here are some ideas to optimize the build&test process within Eclipse, regarding Web projects.


First of all, if your are developing new features that take longer to code, consider disabling the "Build automatically" check in Eclipse. Continuous recompilation just adds unnecesary overhead to our computer. And if memory is scarce or, as it happens often, we have an additional myriad of applications open at the same time, it consumes resources and slows down the system. After all, Ctrl+B does a incremental backup as well, but at user's will.


On the other side, if we are debugging and making many small changes, Build Automatically is the recommended option, as we will see afterwards.


Secondly, if you are working on a Web project, disable autoreloading. By default, projects compiled get automatically published and in turn, projects configured (i.e. on a Tomcat server) get automatically reloaded. That means, ¡ the server is shut down and restarted again ! This is often cumbersome, specially if we are working with a system which takes time to get up and running. Let the developer decide when he wants the server to be restarted.


To disable automatic reloading, do the following:
- Double-click on the server.
- Click on the Modules tab.
- From the listed modules, select the one we are working on.
- Click on "Edit".
In the popup window shown, unselect "Auto-reloading enabled":




Publishing (to the server) gets done automatically after compilation, which is fine since we normally want to publish after a successful compilation and if not, it is a fast operation anyway. This is also ok if we modify JSP pages.


The third aspect of this comes when we are debugging and want to make many small changes that we want to test frequently. How can we avoid restarting the system after every change? The answer comes from the Hot Code Replace (HCR) feature of Eclipse. HCR allows to replace one class for another as long as we don't change its signature, that is, we don't declare new methods or fields. But if we just modify the body of a method, then normally Eclipse will rebuild the class, publish it and restart the debugger at the beginning of the method (provided we had stopped on a breakpoint inside this method). This is much faster, don't you think?


Invest 5 minutes of your time to test these settings, and you will get a fast payback!



No comments: