Spring boot devtools - Static content reloading does not work in IntelliJ - java

When building my first Spring Boot app, I discovered that I need to restart my app every time I make a change to a Javascript file in /resources/static/some-file.js
This is very time consuming.
When I move the files to the /webapps/ folder, it works as expected, but the files are not packaged in a JAR. The docs mention this, so I cannot continue this way.
I read all about spring-boot-devtools, and have installed it in my POM, but the hotswapping doesn't seam to be working. I still need to restart the entire app to see a Javascript or CSS file change.
When the app starts, I can see the line LiveReload server is running on port 35729, so spring-boot-devtools must be doing something...
What would be the steps to further investigate what is going wrong?
My guess is that when IntelliJ runs the app, the files are copied, so when I make a change, I'm actually changing the original files and not the ones used by the running app.
PS: I'm using Maven, IntelliJ IDEA 15 and Spring Boot 1.3.3 with the embedded Tomcat server. I'm not sure what command IntelliJ runs to start the app. The IDE is handling this "automatically". Perhaps I need to change my run configuration?

You need to turn on a couple of features in IntelliJ to make this work.
First, there's a project specific setting which you would need to apply on any project you want to use devtools in. Go to Preferences > Compiler and enable "Make project automatically."
The next setting is an IDEA registry setting that applies to all projects.
In macOS (OSX), press Shift+Command+A (Shift+Ctrl+A in Windows)
Type "Registry" in the search box that appears, and select the registry to open it.
Lookup compiler.automake.allow.when.app.running and enable it.
After that, restart your app. You will notice that the project keeps rebuilding with every change you make. When you check out the result in the browser, you will see both static files and code have been updated.

For Windows users the steps are:
1) Go to File->Settings, then to "Build,Execution,Deployment"->Compiler and enable the "Make project automatically" flag.
2) Press Ctrl-Alt-Shift-/ and select "Registry" from the menu that appears. Enable compiler.automake.allow.when.app.running flag.
3) Start/restart the app and observe static content reloading.

For IntelliJ 2021.2 version or above below are steps that you need to follow
Add spring-boot-devtools dependency if not already added.
Enable Build project automatically as shown below
Enable option in Advanced Settings as shown below

On Linux, press:
Ctrl-Alt-Shift-/

For mac users I had to press Command + Shift + A
And restart INTELLIJ after Step1 and Step2 without which the registry option was not appearing.

You can user like bellow:
First Open Preferences.../Settings... -> Build, Execution, Deployment -> Compiler and allow Build project automatically. Image will look like
Second, we change Registry configuration. Press command+shift+A for macOS or if you are using Windows press Ctrl+Shift+A, and search for Registry. enable compiler.automake.allow.when.app.running.Images look like bellow
Registry image look like..
compiler.automake.allow.when.app.running enable image look like
Then Enjoy..

The option is now in Advanced settings:

Related

Eclipse plugin hot deploy

I'm developing an Eclipse plugin, and I test it launching a secondary Eclipse instance using Run As -> Eclipse Application in my project.
So far so good. However, every time I make a source code change (in Java) I need to close this secondary Eclipse instance and start it again to see my code changes being run.
Do you know of any hot deploy option for an Eclipse plugin? It would save me time since Eclipse is slow to load back again and again.
I guess I got used to Tomcat that implements hot deploy. The moment you save your Java source file Tomcat automatically deploys it behind the scenes. It doesn't deploy the whole application, but just the modified class -- something that takes just a few milliseconds.
Using "Debug" instead of "Run" should be enough.
If this doesn't work, check in the Preferences in Java > Debug that "Enable hot code replace" is on.
Also make sure that "Build Automatically" is selected in the "Project" menu. (Or manually invoke "Build" after saving)

Changes in my java code in eclipse not show in application , even after liferay restart

I have a problem in Eclipse 4.7 (Oxygen) and Liferay IDE 3.1 When I alter my source code, my changes have no effect .
Earlier it was working if I restart liferay (was using liferay 2.6 and eclipse Mars and java7) from eclipse but now each time I have to do a dev ant-rebuild and then after starting server the changes reflect.
Have tried solution provided in other links like (Project -> Build Automatically)
add project in Server but nothing seems to work.
Based off your answer to the previous comments I have determined that you are expecting to see something that is no supposed to happen. If your server is running and you make a change to your Java files (any file ending in .java) you will not see the changes in your browser (on the GUI) until your save, compile, and deploy your changes.
So without any additional tools you will need to do the following for ever .java change.
Save changes
Run the ant compile target
Run the ant direct deploy target
You should see the deployment happen in the console and you can now refresh the page and view your changes. It is important to note that depending on your change you may need to restart the application container and clear temporary files.
There are a few exceptions to this.
JSP changes. You can view changes in your JSP automatically.
JRebel. For 6.2 development I cannot stress this product enough. Get a copy of My JRebel. With JRebel you can save your Java changes and see them immediately. This is a 3rd party tool though which traditionally costed 500usd. It is now free though
Sorry, this was too long for a comment. In the thrust of Olaf's comment though, you need to give more detail. Here are some shots in the dasrk and a question:
Upgrade to Liferay 3.1.1 if you haven't.
Do you see messages like the below ones in the log when you save an edited file? How about when you drag the project onto the running server (the server is running, right)?
21:28:01,514 INFO [pool-10-thread-2][BundleStartStopLogger:38] STOPPED com.liferay.docs.guestbook.service_1.0.0 [562]
21:28:01,588 INFO [Refresh Thread: Equinox Container: 40aeefb4-a286-0017-134c-c19af18a2252][BundleStartStopLogger:38] STOPPED com.liferay.docs.guestbook.portlet_1.0.0 [563]
21:28:01,661 INFO [pool-10-thread-3][BundleStartStopLogger:35] STARTED com.liferay.docs.guestbook.portlet_1.0.0 [563]
21:28:01,672 INFO [pool-10-thread-3][BundleStartStopLogger:35] STARTED com.liferay.docs.guestbook.service_1.0.0 [562]
Have you tried restarting eclipse?

IntelliJ 13: Shared Memory Debug Spring Boot application in 1 step

I have a spring boot application. I use IntelliJ 13.
I want to launch my application in debug mode and debug it. I'm on Windows and I'd like to use shared memory. I would like to just be able to click the debug icon, or a single maven goal, and the application launches in debug mode and the IDE attaches the debugger. This is how I am used to debugging most of my java apps.
However, mixing spring-boot and IntelliJ seems to complicate things. IntelliJ seems to want to connect to the wrong process when I push the green "debug" button and I can't find a way to change the shared memory address that the green 'debug' button's functionality is determined to connect to.
The closest I've come is to add jvmoptions to the maven goal in pom.xml, and then if I add a Remote run configuration, IntelliJ lets me specify a shared memory address that matches what I wrote in the pom. This requires multiple clicks to launch the application and then debug it. It works, in a similar way that using notepad.exe to write code also works. Hence my question.
Is there a 1-step solution using shared memory?
Variation of this question:
Debugging jsp with spring-boot and IntelliJ
However the question and answers are limited to using sockets.
The problem was that IntelliJ was using the Maven goal spring-boot:run as the launch configuration, and trying to debug this causes the debugger to attach to the wrong process.
Setting a new launch configuration of type Application and pointing it at the project's class with the main() method resolves this issue.
Thanks to the commentors for suggesting that this was the way to go about it!
A one click solution (tested on IntelliJ IDEA 14.0.1) using Sockets :
Open Run/Debug Configurations, Add a new Configuration of type Remote
On the Before Lauch panel, add a Run Maven Goal with the command line command:
spring-boot:run "-Drun.jvmArguments=-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
The suspend=n option is important to avoid the Maven Goal to be locked waiting the debugger to connect.
After that you will be able to just lauch this debug task and your app will be launched and the debugger will be attached.

Play Framework 2.1 Java/Eclipse: Auto-Reload not working

The Problem/s:
Views are being compiled but hitting refresh in a browser won't show the changes without restarting the server manually.
Changes to controllers compile automatically using ~run but only a manual server restart will update the content on the server.
Changes to routes under conf are only shown after manually restarting the server.
Background:
running on OSX 10.8.3
using Eclipse Juno 4.2.2
Server is launched using play ~run
Only restarting the server will show changes to views, controllers, routes
To be able to make changes without having to restart the server each time I tried (without success):
in the console: clean -> eclipse -> ~run
in the console: clean -> compile -> ~run
shutdown/restart the computer
Tick Refresh using native hooks or polling -> remove classes_managed from Referenced Libraries and add it manually
Questions:
How can the Auto-Reload functionality be restored?
How can this problem be solved on IDEs besides Eclipse?
Further information:
Playframework reload not working Mac OSX
Auto-reloading with Play framework on a network filesystem
Both of them point to JNotify as the cause for auto-reloading not to work. One of the answers (not enough rep to write a comment) mentions how one could "hack Play framework's sbt plugin to make the PlayReloader trait behave as if JNotify wasn't available." How could one achieve this?
The following got Play's auto-reload to working with Eclipse:
In Eclipse Preferences go to General → Workspace. Uncheck Build automatically.
Restart OS X.
For whatever reason, I had to restart OS X to get akim's suggestion to take hold.
I got around this problem by changing the project configuration in Eclipse. I unchecked the "Allow output folders for source folders" option, which means that Eclipse will compile classes to the "bin" folder. This prevents the Eclipse compilation from interfering with the Play compilation. The only downside is that you have to remember to redo it if you ever do play eclipse again.
Following akim's suggestion, disabling Build automatically under General\Workspace in the Eclipse Preferences solves the problem and re-enables Play!'s auto-reload functionality in all of the above problem cases.

How do I lock Run Configuration in Eclipse?

Eclipse Juno SR2 (and previous versions as well) regularly breaks my Run Configurations. It removes some of the program arguments, changes ports, etc.
Is there any way to lock Run Configuration?
In the Run Configuration dialog, go to the Common tab. Select 'Shared file'. There you can save your run configuration to your project, even place it under source control. That way you can be sure it is unchanged.
Have a look at the "Common" tab of the run configuration, where you can save a run configuration as "shared file" directly in your workspace. Then you can make it read-only, and additionally put it under version control like a normal file and restore it in case of problems.
That said, normally Eclipse plugins do not modify existing run configurations once you have manually changed them, so maybe there is another problem.

Categories