Change Without Redeploying With Eclipse And Tomcat

They say developing Java is slow because of the bloated application servers – you have to redeploy the application to see your changes. While PHP, Python, etc. scripting languages, allow you to “save & refresh”. This quora question summarizes that “myth”.

Yup, it’s a myth. You can use “save & refresh” in java web applications as well. The JVM has the so-called HotSwap – replacing classes at runtime. So you just have to start the server in debug mode (the hotswap feature is available in debug mode) and copy the class files. With eclipse that can be done in (at least) two ways:

  • WTP – configure the “Deployment Assembly” to send compiled classes to WEB-INF/classes
  • FileSync plugin for eclipse – configure it to send your compiled classes to an absolute path (where your tomcat lives)

I’ve made a more extensive description of how to use them in this stackoverflow answer.

Now, of course, there’s a catch. You can’t swap structural changes. If you add a new class, new method, change the method arguments, add fields, add annotations, these can’t be swapped at runtime. But “save & refresh” usually involves simply changing a line within a method. Structural changes are more rare, and in some cases mean the whole application has to be re-initialized anyway. You can’t hotswap configuration as well – your application is usually configured in some (.xml) file, so if you change it, you’d have to redeploy. But that, again, seems quite an ordinary scenario – your app can’t just load its bootstrapping configuration while running.

Even more common is the case with html & css changes. You just can’t live without “save & refresh” there. But that works perfectly fine – JSPs are refreshed by the servlet container (unless you are in production mode), and each view technology has an option for picking template files dynamically. And that has nothing to do with the JVM.

So you can develop web applications with Java almost as quickly as with any scripting language.

Finally, I must mention one product with a slogan “Stop redeploying in Java” – JRebel. They have created a very good product that is an improved HotSwap – it can swap structural changes as well. And has support for many frameworks. The feature list looks really good. While it’s a great product, I wouldn’t say it’s a must. You can be pretty productive without it.

But be it HotSwap or JRebel – you must make sure you don’t redeploy to reflect changes. That is a real productivity killer.

4 thoughts on “Change Without Redeploying With Eclipse And Tomcat”

  1. That hotdeploy would work with tomcat right? does that work with websphere or jboss? or do they have thier own mechanism for hotdeploy.

  2. I’ve used it with Glassfish some time ago. HotSwap is a JVM thing, so it should work with any server. But app servers may have some improvements on that.

  3. I got a question. Why these Hot swap techniques only works when the server started in debugging mode only? By the File sync is working like a charm.

Leave a Reply

Your email address will not be published. Required fields are marked *