之前就了解了Hotswap Agent和DCEVM可以替换jrebel,但一直没有详细了解下,今天写这篇文章,让大家可以在JDK8和JDK11环境下进行idea热部署。
JDK11安装
最简单是使用JDK11在idea开发。大家可以将JDK 11 设置为trava-jdk-11-DCEVM ,具体下载地址如下:
Releases · TravaOpenJDK/trava-jdk-11-dcevm · GitHub
下载完后,将该JDK设置为默认即可。最后将启动程序添加VM参数即可,具体参考下面的图片:
JDK8安装
JDK8安装可以参考这篇文章:
IDEA 使用 DCEVM + HotSwapAgent实现StringBoot热加载_lizmit的博客-CSDN博客_decvm+hotswapagent
JDK1.8的181版本可以到这里下载:
https://download.csdn.net/download/penker_zhao/86800226
配置的时候,请指定HotswapAgent 为1.4.2-SNAPSHOT,下载地址是:
Releases · HotswapProjects/HotswapAgent · GitHub
将Agent installation换成下载的1.4.2-SNAPSHOT.jar,比如
D:\Java\dcevm-11.0.15+1\hotswap-agent-1.4.2-SNAPSHOT.jar
这个解决了DCEVM的Hibernate插件报错问题。
通过上述设置后,就可以使用跟JRebel相似的热加载功能,成功后截图如下:
如果涉及的源码修改,修改完后,重新编译源码,即可重新看到编译新的class文件
顺便可以看下DCEVM打的广告词:
We need to use special java agent together with our JVM to enhance ability of reloading of changed classes. For example:
- JRebel (too expensive $550 😨 per year per user)
- Spring-Loaded (cannot work properly with java 8 and
crash JVM
😵, the Spring team propagates the "Restart application on file-change"-approach of spring-boot-devtools for Spring Boot) - FakeReplace (No JDK10+ support yet)
- RelProxy (Dead? No support for JDK8+)
- DCEVM (free-opensource-really
hot
😀)
We will choose: DCEVM + Hotswap Agent 👍