DCEVM - A JRebel free alternative
If you work for a company that buys you a commercial hot-swap solution, like JRebel, you're lucky because usually they work out of the box and offer more functionalities. But if not, don't worry, there are free alternatives out there (DCEVM, FakeReplace, Spring-loaded...). I haven't tried them all, but it looks like DCEVM is the most advanced one and yet requires minimal configurations.
The key is how to set it up, because unfortunately, the project website hasn't been updated and the binary setup hosted there doesn't work with JDK/JRE 1.7 (if it works for you anyhow or if you can build the binary yourself, congrats you can skip the steps 1-3 below).
Update May 10 2014: Great news: there is a new DCEVM fork and the binary installers for JDK/JRE 1.7 are now available, thanks toAfter hours digging around and trying different ways of using the new VM, I managed to make it work without having to build my own installer. Needless to say, I was very excited and couldn't wait to share with my fellow developers here how I did it.
Here is the catch: don't use the installation file from the official website to patch your JRE, it's obsolete and may not work with your version of Java. The quickest way is to get the pre-patched JRE here and just use it as your server runtime, no need to mess with your current JRE. Here are the steps:
- Download the pre-patched DCEVM for your platform. Extract it to somewhere on your hard drive, say,
C:\dcevm. Setup a runtime for this new JRE in your Eclipse by going toWindows >Preferences >Java >Installed JREs >Add >Standard VM. Click Directory and browse to your dcevm extracted location. Click Finish.
- Create a Server Runtime that use your new JRE: Go to Windows>Preferences >Server >Runtime Environment >Expand Apache node and choose your Tomcat version of your choice then click Next. Browse to your Tomcat installation directory, then choose the dcevm as JRE.
- Create new Tomcat server instance. Choose your newly created Runtime in the Server Runtime Environment dropdown. Click Finish.
- Add your web project to your new server. After that, in the Servers tab, double-click your server. In the configuration page, go to Modules tab. Choose your web module, click Edit and disable auto-reloading by unchecking the checkbox > OK.
- You're done. Now start your server in debug mode. Make some changes to your Java class, hit refresh on your browser to see the change reflected immediately.
DCEVM is definitely my hotswaping tool of choice now. I can't imagine developing my Java application without it. One good news is the guy behind the project now works for Oracle and he made an enhancement proposal for it to be integrated into the JVM. See JEP-159.
While this tool is a great time saver when you work on your code, it is not recommended to be used in production (again, that's perfectly fine for me).
Happy coding guys! If you have your own approach or any tips to the reloading problem, feel free to share them here in the comment section.
Update April 12 2014: For some reason, the site http://dcevm.nentjes.com I mentioned above has stopped hosting DCEVM pre-patch binaries. Too much traffic could be the reason, as seen with some Dropbox accounts hosting DCEVM binaries. I hope someone would be nice enough to work on something to replace the http://dcevm.nentjes.com above. In the mean time, here is what I found: