How to enable Spring Boot Live Dev Tools on IntelliJ 2021.2 to rebuild classes after modifications and deploy changes to server?
Asked Answered
S

3

18

This is a tutorial on how to enable Dev Tools project on IntelliJ 2021.2 and observe the changes in code without having to restart the Tomcat server.

Shellashellac answered 5/10, 2021 at 11:49 Comment(0)
S
43

In order to make it work, you need to:

  1. Have devtools enable in maven or gradle. In maven it looks like :
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
         <scope>runtime</scope><!-- -->
        <optional>true</optional>
    </dependency>
  1. In IntelliJ IDEA: go to settings(ctrl + alt + s) -> Build, Execution, Deployment -> Compiler, check "Build project automatically"

  2. Enable option "Allow auto-make to start even if developed application is currently running" in Settings -> Advanced Settings under "Compiler"

check Allow auto-make to start even if developed application is currently running under Advanced Settings

You can now restart your intelliJ IDE and start your application.

Shellashellac answered 5/10, 2021 at 11:49 Comment(1)
If there is no Advanced Settings section you can try change registry flag from registry. 1- Double shift and search registry. 2- set true the value of compiler.automake.allow.when.app.runningScourge
T
4

1.file->settings->Build,Execution,Deployment->compiler->click->Build project automatically->apply->ok

2.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
     <scope>runtime</scope><!-- -->
    <optional>true</optional>
</dependency>

3.file->settings->advance option->allow auto make start even if developed application in currently running->apply->ok

4.restart IDE

Tribadism answered 7/10, 2022 at 18:43 Comment(1)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope><!-- --> <optional>true</optional> </dependency>Tribadism
S
2

Set Up your Project and IDE.

  1. Add the POM dependency.
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
  1. In IntellijIDEA: File -> Settings... -> Build, Execution, Deployment -> Compiler: Check "Build project automatically"

  2. In IntellijIDEA: File -> Settings... -> Advanced Settings: Check "Allow auto-make to start even if developed application is currently running"

Set Up your Browser.

  1. Add the "LiveReload" extension to your browser. Eg: if you are using Chrome Brower add the "LiveReload" extension by livereload.com.

  2. Initially when you start your app, load in a browser tab and hover over the 'LiveReload' extension to ensure it is enabled. The tooltip should show as "LiveReload is connected, click to disable Has access to this site". LiveReload Tooltip

Once these are set up, to ensure both Automatic Restart and LiveReload;

  1. Do changes to both the Static files and Java files in the application that is already running.
  2. Build the project (Build -> 'Build Project' or Ctrl+F9).
  3. Observe the application automatically restarting with "LiveReload server is running on port .. " in the IDE console and the browser is refreshed.
Salot answered 27/12, 2022 at 4:10 Comment(1)
I see a ClassPathChangedEvent in the logs when I run build, but the changes are still not reflected. For testing, I implemented a simple Spring Scheduler and changed the log message printed every second. And also, do I need to run Build Project whenever I change something? because that's not really any gain compared to restarting the application. Using Quarkus for example, it will apply code changes when the file gets changed automaticallyRavel

© 2022 - 2024 — McMap. All rights reserved.