Question
When developing a Spring Boot project, how to automatically reload changed classes in IDEA?
Answer
Note: This solution only applies to a Java project.
The IDEA only supports hot reload changed classes in the JVM(which is supported by the JVM) at debug mode; if you need hot reload resource/configuration files, you may try third-party company solutions such as JRebel(Paid).
Please enable the File | Settings | Tools | Actions on Save | Build project (which is the same as Settings | Build, Execution, Deployment | Compiler | Build project automatically) and File | Settings | Advanced Settings | Allow auto-make to start even if developed application is currently running.
In the File | Settings | Build, Execution, Deployment | Debugger | HotSwap page, enable options:
Build project before reloading classes
Enable 'JVM will hang' warning
The Oracle/OpenJDK doesn't support every type of code modification; some big changes, such as modifying parent classes and static fields, are not supported, and this will cause the JVM to crash/restart.
As so far know, there is something like JRebel(paid software) or open-sourced https://github.com/HotswapProjects/HotswapAgent plus JBR https://github.com/JetBrains/JetBrainsRuntime/releases, it needs some configuration to add JVM params like -XX:+AllowEnhancedClassRedefinition -XX:HotswapAgent=fatjar
If changed classes are not reloaded after an automatic build, check Reload classes after compilation in File | Settings | Build, Execution, Deployment | Debugger | HotSwap. When it is set to Ask, automatic builds skip the reload. For details, see HotSwap in IntelliJ IDEA.
Comments
0 comments
Please sign in to leave a comment.