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.
Related
Is it possible to open 2 or more projects, in different IntelliJ instances, and debug across them?
For example:
I start debugging on Project A. Project A calls a method in Project B. I want my debugger to continue on Project B on the other window.
I know a way to debug across multiple maven projects, is to add all the projects to the same IntelliJ instance. But I would like to know if there is a way to do it, without adding all projects to the same instance. To break up the projects in its own IntelliJ windows.
Yeah it is possible
First create a remote debug configuration: Edit configuration -> Remote.
You will see a command line argument which you have to copy and paste it to the script that you made to run your java file.
Keep in mind, to make sure your Project B doesnt starting running before your turn your debugger on, change suspend=n to suspend=y.
Once your parent java file runs go to the secondary idea window and run the remote configuration that you created in first step. If everything is right, your code will stop at the breakpoint.
I have multiple spring boot applications in a single IntelliJ project. And i want to have a single button to run all of them in some order.
I know there is an option to Run Another configuration before launching the original one, so in that way the configurations can be chained.
But when i use it, it runs that Another Configuration and doesn't run the original one.
So I'm wondering if anyone met this issue and how it was resolved?
You could create a Compound run type and add all your applications in it. That way you can just run that config and all your apps will start.
Update April 2016:
Multirun Plugin says:
Prefer to use built-in support starting from IntelliJIdea 15 https://www.jetbrains.com/idea/help/run-debug-configuration-compound.html
Stéphane's answer works great but if you need additional features you can install the MultiRun Plugin that will allow you to do the same as the Compound run type but with more bells and whistles.
https://plugins.jetbrains.com/plugin/7248
For instance:
You can set a delay between each configuration run or run one configuration after another using the Before Launch feature.
See here for more info about how to setup: https://github.com/rkhmelyuk/multirun/wiki/How-to-run-configurations-with-Multirun
Update April 2018:
On the "Run configurations" combo box, click "Edit Configurations". Then uncheck "Single instance only" option. Then click "Apply".
Then you can click the button "Run" any times you want, launching a new instance each time.
IntelliJIDEA Ultimate 2018.1
Env:
IntelliJ IDEA 2021.1.3 (Ultimate Edition)
Steps:
Go to Run configurations combo box.
Click Edit Configurations....
Check Allow parallel run option.
Click OK.
Yes you can achieve this by launching a standalone java app which will spawn multiple threads per microservice and start them. You can find a sample code [here]: https://github.com/rameez4ever/springboot-demo.git
Another note to reduce ambiguity:
What was called Run Dashboard in a lot of sources in the past is now called Services.
it's called allow parallel run as of 2018.3 instead of Single instance only
Package the application using mvn package.
Go to the folder where the packaged application jar is stored
Run java -jar [NAME_OF_THE_APPLICATION_JAR]
--server.port=[DESIRED_PORT_NUMBER]
OR
Go to the application root directory
Run: mvn spring-boot:run
-Drun.arguments="--server.port=[DESIRED_PORT_NUMBER]
That way you can start multiple instances of the same microservice at the same time using different port numbers.
Yes.
Goto "Run configurations" combo box, click "Edit Configurations".
Then unchecked "Single instance only" option. Then click "Apply"
For Eureka Server:
1.Run the application without serve.port.
2.Add server.port =9999 in application.properties. Run the application.
Now browse Eureka dashboard, you will have 2 instances running.
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:
I am running Netbeans 8.0.2 and I am trying to debug a web app. This app is a module in a larger suite. Normally just the parent gets compiled which set's up property values for db connections etc. So, that being said the web app I am trying to debug never gets built independently.
So, I want to be able to do right-click > debug without netbeans running the maven build (this will mess up the prop values).
I have the "Always perform build before running application" unchecked in the Run configuration. But every single time, it builds it anyways!
Is there something I'm missing? Or is there some bug in Netbeans?
Edit: I've also tried deleting the cache.
I know this is an old question which you probably (and hopefully) solved already. However, as I had the same problem and could not find an answer here, I want to share my solution to this problem for others.
My application also first built itself and then started debugging. I checked the run/debug configuration and they were fine. So I deleted the local maven repositories of all dependencies of my application and rebuilt them. Seems like NetBeans confused something with the dependencies and therefore rebuilt the application every single time again. After deleting and rebuilding the dependencies I was able again to debug the application without building it before.
usually when I debug java by pressing on the bug icon, it starts debugging right away and goes to the debug perspective...
but now everytime I click on the bug icon, it always opens up the debug configuration window rather than actually debugging....
any idea as to how to make it debug right away once again?
This usually happens if you have configured Eclipse to "Always launch the previously launched application" (Preferences>Run/Debug>Launching) but Eclipse can't find a previously launched application. Does this happen again if you configured the debug configuration once, debugged successfully with this configuration and then try to rerun it?
Or you could change this setting so Eclipse always tries to run/debug the currently opend file, then it will behave like Ed described it.
If it has a saved configuration for the currently active file in the editor, it will automatically use it. Otherwise, it will want you to tell it what you want. I'd suggest getting in the habit of using saved configurations (down-arrow on the debug button) that you've set up.
You could install 'Eclipse Runner' via marketplace. It's a nice addition of run/debug feature.
I faced the same problem. I defined the debug configuration and run my Junit but my eclipse was crashing again and again.
I restarted my eclipse and my debugAs menu is back to two options [Debug on server or debug as Junit].
Hope it might help.