Blogs
I hate when I have to spend time deploying changes in my Java classes. I wanted to know if there was a way of deploying them very fast.
So I found out about Hotswap Agent and DCEVM and decided to give them a shot. So far, they meet my expectations. They get the job done fast... it seems instant! I would encourage anyone developing in Liferay to give it a try, and warn you that you might not want to live without it afterwards
Long story short, HotswapAgent and DCEVM are two Open Source projects that, when working together, allow reloading almost any Java class change instantly in the JVM when saving your code. Hotswap Agent is the library in charge of the class reloading, while DCEVM is a JRE patch needed for this to happen. I extraced the summary from here: http://www.hotswapagent.org/how-does-it-work. You can find more info about both technologies on the Internet, but here I will focus on showing how to make them work with Liferay.
So this is what I am currently using:
- Liferay Portal version 6.2.4 CE ga5
- DCEVM for Java 7u79 (note: there is also a version for Java 8 available) – Download from: https://dcevm.github.io/
- Run Java SDK 7u79 (matching the version for the DCEVM patch) - http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
- HotswapAgent – 0.3 stable https://github.com/HotswapProjects/HotswapAgent/releases
- Maven 3.2.3
There is the catch of having to install a patch in the JRE, but since there are versions available for Java 7 and Java 8… I think it is worth it to use it for local development. These are the steps to install and run it:
1) First of all, download a copy of Java SDK 7u79, matching the current version of the Java 7 DCEVM available. I suggest this because I couldn’t make it work with a different Java SDK 7 version. I recommend you to download the SDK and make a copy of it in the same folder for you to apply the patch. That way you will keep an unpatched Java SDK handy:
2) Install the DCEVM JRE patch in the copy of the SDK and download the Hotswap Agent jar. The DCEVM installation UI is quite easy to follow. Select your java SDK target of the DCEVM patch, and click on “Install DCEVM as altjvm”. That’s it. Follow the Install section here if you need: http://www.hotswapagent.org/quick-start.
3) Configure Tomcat Liferay server to run Hotswap Agent in the patched JRE and pass Tomcat the following Memory Arguments:
-Xmx1024m -XX:MaxPermSize=512m -XXaltjvm=dcevm -javaagent:F:\software\DCEVM\hotswap-agent.jar=disablePlugin=hibernate,disablePlugin=proxy,disablePlugin=tomcat
(specify the hotswap-agent.jar location properly to yours)
This Stack Overflow might help you on this step: http://stackoverflow.com/questions/32485303/how-to-configure-hot-swap-agent-with-liferay-server.
The disablePlugin arguments can be needed to disable certain plugins of Hotswap Agent that could cause errors. I was getting NullPointerExceptions when saving Java classes at some point, and disabling those particular plugins makes it work: proxy, hibernate and Tomcat. Follow this thread to know the error I was getting if it helps: https://groups.google.com/forum/#!topic/hotswapagent/YNWV0D7qgSc
I have tested these tools for a week now, and I am very happy with how they work together: I can say that I don’t spend any time now deploying most of my Java changes. I hope you find this useful and enjoy Java fast deployments
NOTE 1: it doesn’t instantly reload Java changes in JSP pages. If you change them, you will need to build and deploy again.
NOTE 2: any questions, feedback or input will be appreciated: if anyone runs into issues setting it up, i will try to help.
NOTE 3: Java classes of action hooks are benefited of this instant reloading. So if you deploy an action hook, do some changes in the Java class extending Action, and then save, the Java class is reloaded instantly.