Technology Sharing

IDEA implements hot deployment

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

What is hot deployment? Hot deployment means that during the running of an application, there is no need to stop the entire application or restart it.server, you can deploy new code, resources or configuration files and make them take effect immediately. This deployment method helps improve development efficiency and system availability.

With hot deployment, when a part of the code is modified, the incremental content can be automatically compiled and deployed without restarting the project. You only need to refresh the browser to see the effect of the updated code modification. This greatly improves development efficiency and simplifies waiting time.

How to implement hot deployment? In IntelliJ IDEA, there are several common ways to implement hot deployment:

  1. Automatic compilation and deployment: IDEA supports automatic compilation and deployment by default. When you modify the code, IDEA will automatically compile the modified files and deploy them to the running application. Make sure the automatic compilation feature is enabled in the project settings.
  2. Use JRebel plugin: JRebel is a commonly used hot deployment tool that allows you to immediately see the effects of code changes without restarting the application. In IDEA, you can install the JRebel plugin and configure the project to enable hot deployment according to the documentation.
  3. Spring Boot DevTools: If you are using Spring Boot, you can use the hot deployment feature provided by Spring Boot DevTools. Add Spring Boot DevTools to the project dependencies and make sure to enable it in IDEA.Enable automatic compilation

The ones used in this article areSpring Boot DevTools。The IDEA software version is 2023.2.3.

Step 1: Introducing dependencies

Introduce the spring-boot-devtools dependency in the pom.xml file in the Maven project.

Code language: html

copy

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-devtools</artifactId>
  4. <scope>runtime</scope>
  5. <optional>true</optional>
  6. </dependency>

Step 2: Write configuration

Write the configuration in the yml file.

Code language: html

copy

  1. spring:
  2. devtools:
  3. restart:
  4. enabled: true

Step 3: Set up the project automatic compilation function (static compilation)

1. Hot deploy the current project

Right click: File --&gt; Settings --&gt; Build,Exec.... --&gt; compiler --&gt; check Build project automatically. As shown in the figure.

 

26e991e237e4dfb810d269ce54aee854.png

Build project automatically: Automatically package the project and click Apply.

2. Hot deploy the newly created project (optional)

Right click: File --&gt; New Projects Setup --&gt; Settings for New Projects --> Settings --> Build,Exec.... --> compiler --> 勾选Build project automatically。as the picture shows.

 

0fbe8f5d96f29b44aeaa1e05fe564bda.png

The remaining steps are the same as above, so I won’t post screenshots here.

Step 4: Enable hot deployment during operation (dynamic compilation)

Right click: File --&gt; Settings --&gt; Advanced Settings --&gt; Check Allow auto-make to start even.....

 

5f5192a1e3eead141fe2f979ae56886c.png

Click Apply.

After changing the project code, return to the page and refresh it to see the effect of hot deployment.