Remote debugging Spring Boot App

I have an application running on a remote server and I need to debug it. Don’t worry, server is firewall-ed and access is strictly controlled.

What we want to achieve is to run the spring boot application in debug mode. We need to tell the VM to run in debug, how we will connect to it and on what port it should listen. It is very simple to do, if you know where to look for an answer.

Following was tested with SpringBoot 2.1.7 and IntelliJ. Example project is on github.

Server setup

To enable remote debugging, you can try this

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
	</configuration>
</plugin>
		
	

Or just pass the command line arguments

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

I will put the links to the docs, but in short, this says start the java debug protocol, use network socket for connections, listen for incoming connections (start as a server) on port 5005 and suspend=y means wait for debug connection at startup. This last one might be interesting, if you want to debug some bootstrapping process!

IntelliJ setup

Follow the steps:

  • Run -> Edit Configurations -> Click ‘+’ to add new configuration -> Pick ‘Remote’
  • Now, enter the Host address (for localhost put localhost) and port, for our example its 5005. Save and close
  • Go to Run -> Run -> Select your Remote debug configuration and click Debug
Adding remote debug configuration
Starting remote debug configuration

Resources

PS If you are debugging a packaged .jar application, you can start like this:

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n -jar app.jar