tomcatservletsspring-bootintellij-ideaspring-boot-devtools

Run Intellij/Tomcat/SpringBoot DevTools in background (i.e. no focus on IntelliJ window)


I have a web application. I mostly used notepad++ for development. I need to use Intellij to run two Tomcat servlets. My ideal set up is to run the two serlets in IntelliJ and then minimise and never use intellij again (i.e. make my changes in notepad++, save. then just refresh my browser tab).

To stop myself from having to rerun the servlets every time I make a code change, I set up springboot devtools and added configuration below:

I followed this link: https://dzone.com/articles/spring-boot-application-live-reload-hot-swap-with (had to alter the first step to do the same thing but with gradle i.e. add

compile("org.springframework.boot:spring-boot-devtools")

to the gradle.build (the correct one, not any random one).

then after finishing the rest of the steps from the link, added this line to application.properties:

spring.thymeleaf.cache= false

THEN when running the tomcat servlets in DEBUG mode

After doing all of the above, this works by: when servlets are running in intellij -make your UI code change -save it (in my case i was using notepad++ not intellij - go back to intellij (just bring the window into focus) - then go back to browser and refresh the browser

Currently, my code changes will only be applied if I bring the Intellij window into focus before refreshing my browser. Is it possible to set something up so intellij doesn't need to be in focus?

i.e. open intellij, run my two servlets, then minimise it and never touch it again. I want to ignore it and carry on just using my browser and notepad++ for dev work


Solution

  • This isn't possible as far as I know. The Spring boot Devtools will hot reload as soon as the project is built.

    In IntelliJ, the project won't automatically rebuild, but this can be configured by enabling Build project automatically (compiler.automake.allow.when.app.running).

    However, even when you enable this, IntelliJ will only build it automatically if it detects a change. If you change a file in IntelliJ, this will count as a change. However, when you change a file in another editor like Notepad++, it won't.

    Luckily, IntelliJ synchronizes files from disk at certain times. By default, IntelliJ is configured with Synchronize files on frame or editor tab activation, so it will synchronize the files as soon as an editor is opened.

    This is what you're experiencing. However, you can't change synchronization to always happen since that would require quite some I/O and CPU.There are some plugins like the Auto Sync plugin, that may allow you to customize when the synchronization happens.

    Alternatively, if you edit the files in IntelliJ (and not in Notepad++), you wouldn't need to synchronize, and thus you wouldn't have this problem.