It usually takes a lot of time whenever you’re recompiling a Java web project. The IDE would usually recompile the entire project, package them into a war and have it redeployed on your application server (i.e., Tomcat) then letting the server reinitialize itself. It takes a lot of time, and it just gets worse as your project grows bigger.
Uh, Hot Swap?
Getting Hot Swap to Work
While in a fully-functional IntelliJ Java web project*
- Get the updated, forked version of DCEVM here: http://dcevm.github.io/
- 64-bit is supported!
- Works in Linux with matching build numbers
- While unsupported, it’s currently working on Oracle Java JDK versions as well.
- Run the package, and choose Install DCEVM as altjvm
- In IntelliJ, under your project’s build configurations (Run -> Edit Configurations), make sure that your project uses exploded war artifacts, instead of the normal war packages.
- The use of exploded war packages allows IntelliJ to update both classes AND resources whenever they are updated. That means this change will also help you in swiftly reloading JSP pages that have been updated.
- In the Server tab, add -XXaltjvm=dcevm to the VM options (seems to me this is optional.)
- Change On ‘update’ action and On frame deactivation to Update classes and resources.
- These changes will ensure that IntelliJ will update whenever changes are made and when you’ve shifted the focus away from IntelliJ. If you don’t want to do this automatically, then set Do nothing for these options.
- IntelliJ will make and compile any classes you’ve changed once you’ve switched your focus away from the IDE. Your changes will reflect as soon as you refresh the page.
- If you’ve used HotSpot VM before (the default Hot swap), you’ll be able to create new classes and methods in both new and existing classes. Give it a try.
- Frameworks like Spring and Hibernate are likely not fully supported, due to the nature of how they work or how they are brought up (and how it might be improperly done by hot swapping). It’s workable, but you just have to be careful when to modify or add code that relies on these frameworks.
- If you REALLY need to, then JRebel has support for it. Unfortunately, JRebel costs money and DCEVM being free is the exact reason why I wrote this post.