Several ways for IDEA to realize hot deployment

Hot deployment makes it possible to load the changed code without restarting the server after modifying the code.

  • Type 1: Modify the server configuration so that when the IDEA window loses focus, update classes and resources

    Menu Run -> EditConfiguration , and then configure the specified server, on frame deactivation = Update classes and resource under the server tab on the right.

    Pros: Simple

    Disadvantages: Hot loading based on JVM only supports code modification in method blocks, only in debug mode, and when idea loses focus, hot loading will start, and the relative loading speed is slow

  • Type 2: Use springloaded jar package

    a. Download the jar package, github: https://github.com/spring-projects/spring-loaded

    b. Add VM startup parameters when starting the application: -javaagent:/home/lkqm/.m2/repository/org/springframework/springloaded/1.2.7.RELEASE/springloaded-1.2.7.RELEASE.jar -noverify

    Advantages: good support for Spring series frameworks (excluding Spring boot), support for member-level modifications (add, delete, and modify methods, fields, annotations), and support for enumeration value sets.

    Disadvantages: as opposed to advantages

  • Type 3: Use the developer tools provided by spring-boot-devtools

    The following dependencies are introduced into the spring-boot project

    <dependency>
            <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>

    Advantages: Simple, supports Spring-boot projects, and supports hot deployment of member-level modifications.

    Disadvantage: Only supports spring-boot projects.

  • Type 4: Use the Jrebel plug-in to achieve hot deployment (the plug-in is a 14-day free trial)

    Online installation: Menu File -> Setting -> Plugin, click Browse repositories at the bottom right, enter: JReble for Intellij at the top of the pop-up box, and select Install.

    Advantages: Powerful, supports various frameworks, and provides IDE plug-ins.

The last three methods are based on the class loading mechanism to achieve hot loading. Therefore, after you modify the code, you must recompile the current code to trigger hot deployment. Eclipse supports automatic compilation by default, while in Intellij IDEA, automatic compilation is turned off by default. Compiled, you can set it up according to the following 2 steps:

  1. IDEA enables automatic project compilation, enter settings, Build, Execut, Deployment -> Compiler Check the Build Project automatically on the left
  2. IDEA enables automatic make when the project is running, ctrl + shift + a search command: registry -> check compiler.automake.allow.when.app.running

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324651446&siteId=291194637