18

After fiddling around for way too long till I got proper debuging setup in Netbeans 8.2 with Spring Boot 1.4.3 I figured I write down my findings as Q&A for others.

The problem is that the default configuration for Netbeans fails to properly launch Spring in debug mode and when you search the internet you only find the outdated information in the Spring docs that won't work.

The solution is simple if you know how. Please find the correct setup instructions below.

TwoThe
  • 13,879
  • 6
  • 30
  • 54

5 Answers5

27

Tested and works with Netbeans 8.2 and Spring-Boot 1.4.3:

First of all make sure you have the Spring Maven plugin included (this should be already included when making a new Netbeans Spring project):

<plugins>
  ...
  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>repackage</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
  ...
</plugins>

Also it is a good idea to include the Spring Devtools like this:

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

Now navigate to your project settings -> Actions -> Debug project and set the following:

enter image description here

Execute goals:

spring-boot:run

Set properties:

run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.listen=true

Now run your application via the usual debug button and Spring should properly connect to the JVM debugger.

Spring Boot 2.x

To enable Netbeans debugging for a Spring Boot 2.x project (and more specifically version 2.x of the spring-boot-maven-plugin) the procedure is exactly the same, except the run.jvmArguments property name has changed to spring-boot.run.jvmArguments:

spring-boot.run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.listen=true
MattV
  • 28
  • 5
TwoThe
  • 13,879
  • 6
  • 30
  • 54
  • 4
    It's doesn't work for me... When I run in debug mode the debug-output print "JPDA Listening Start..." and nothing happings... You have any idea what's happing? – Rafael Gomes Francisco Mar 29 '17 at 20:22
  • This works OK, except "step into" behaves more like "step over" -- can't find a way to actually step into anything :( – Magnus Nov 11 '17 at 14:46
  • I want to point out also that you actually you don't need spring-boot-maven-plugin if you are using spring-boot-starter-parent. – zygimantus May 03 '18 at 11:00
  • Since version 2.0.0.M3 of the spring-boot-maven-plugin, you need to change `run.jvmArguments` to `spring-boot.run.jvmArguments` See https://github.com/spring-projects/spring-boot/commit/4510be0f8f1af1f907d329fcf1bc7b4d00772ef2 – lolo101 May 09 '19 at 19:48
  • For some reason the debugger does not stop at breakpoints. I'm using spring boot v 2.1 & netbeans 11. any tips? – letimome Jun 27 '19 at 08:27
  • Works with Spring Boot 2.1.6 and Netbeans 12. – scriptfoo Dec 19 '20 at 22:41
4

Testing NetBeans 8.2 and Spring Boot 2.0.1, I was not able to make things work following @TwoThe's instructions. First, I encountered an issue where all I saw was "JPDA Listening Start..." in the output window. To resolve that problem, I added Spring Devtools as an optional dependency. Second, even though debugging appeared to be running okay, the "Debugging" window, which normally displays the list of active threads, was empty and breakpoints that I set were not triggered. Third, attempting to stop the debugging session by pressing the red "Finish Debugger Session" button would not stop the Tomcat server.

Instead of changing the execute goals to "spring-boot:run", I found that it was sufficient to use the default "Debug project" action execute goals:

process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec

.. and properties:

exec.args=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ${packageClassName}
exec.executable=java
jpda.listen=true

(As a sidenote, debugging as a regular Java application is apparently the recommended approach to debugging Spring Boot applications in Eclipse; see How to debug Spring Boot application with Eclipse?)

One helpful tip is that if you want to debug using a certain Spring Boot profile, say "debug", you can prepend "-Dspring.profiles.active=debug " to the "exec.args" property. See also: Spring boot running a fully executable JAR and specify -D properties

Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
  • Using this config gives me java.lang.ClassNotFoundException and java.lang.NoClassDefFoundError errors. Maybe I need explicitly specify classpath? – zygimantus May 03 '18 at 11:52
  • @zygimantus Which class is not found? I have now added the default properties. Maybe try those. – Daniel Trebbien May 03 '18 at 17:43
  • Well those classes are generated by my project during Maven generate phase. I wonder why this issue came up for me... – zygimantus May 04 '18 at 06:41
  • It works better with Netbeans 11.2 or 11.3 especially if you are using SpringBoot and maven. Very easy to switch – Pascal Fares Apr 13 '20 at 08:19
1

enter image description here

Tested on NetBeans9

Action: Add any name Set Properties: select Add> button, select Debug Maven Build And debug as always -> IDE debug button

mdrafiqulrabin
  • 1,657
  • 5
  • 28
  • 38
0

If you are still having the problem after applying all above mentioned fixes, remove all your breakpoints and try again. Window -> Debugging -> Breakpoints -> Delete All Breakpoints

hirantha129
  • 559
  • 1
  • 8
  • 19
0

POW

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

buld

<build>
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
                          
                            <executions>
                                <execution>
                                  <goals>
                                    <goal>repackage</goal>
                                  </goals>
                                </execution>
                              </executions>
    </plugin>
</plugins>

Debug Project

  • Excute Goals : package

  • Set Properties:netbeans.deploy.debugmode=true netbeans.deploy=true

Change

  • Excute Goals : spring-boot:run
  • Set Properties: spring-boot.run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} jpda.listen=true

and Netbeans Press debug project -- not navigator--> spring-boo-run ... What was the difference? spring-boot.run.jvmArguments: