Remote debug or local debug with tomcat embedded in Spring boot

Viewed 1040

I am working on a new project which embedded a tomcat with the dependency spring-boot-starter-tomcat:2.5.3 (into vaadin-spring-boot-starter). I am building my project into a .jar, and launching it with "mvn spring-boot:run".

But because of the embedded tomcat, I am unable to use the debug mode with Eclipse.

I have already try to launch a remote debug session, with :

MAVEN_OPTS= -Xmx1024M -XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

Eclipse connects itself well, but breakpoints are not working and it shows me only one thread, without any more informations.

So, do you have any idea how can I make it works ? Thanks you for your time !

4 Answers

When running application using mvn spring-boot:run you can attach debugger like this:

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:8000"

By providing spring-boot.run.jvmArguments system property.

Alternatively, you can build application first and then run it using the following command:

java -jar app.jar -Dagentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000

When you provide debugger configuration using MAVEN_OPTS, the debugger is attached to the Maven process, however, the application is running in a separate Java process without a debugger attached.

The easiest way to debug a Spring Boot application from an IDE is to not use Maven at all but instead directly launch the main method from the @SpringBootApplication class.

As a third solution, I have installed Spring Tools 4 on the Eclipse Marketplace. It makes me able to launch a @SpringBootApplication in debug mode, like Leif Astrand said, but with an IHM (Boot Dashboard).

Another solution is described here: https://vaadin.com/forum/thread/17519592/debug-with-intellij This solution also helped me get around the problem of connecting the remote debugger, but breakpoints not being reached (see my comment above).

You can add a JVM arg to the config params of the plugin, like this:

     <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <!-- my edits start -->
        <configuration>
            <jvmArguments>
                -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
            </jvmArguments>
        </configuration>
        <!-- my edits end -->
    </plugin>
Related