Navigate back to the homepage

How-to debug JVM applications remotely

Sergey Pogorelov
February 4th, 2020 · 1 min read

Sometimes it might be useful to debug remote applications that run on the remote server and not your local machine.

In order to do that you need to use the following JVM options and connect with debugger.

1-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1045

Notice that here you can change 1045 to be any port what you want. And suspend option is y so your application won’t start work without connected debugger.

Let’s test it

The good news that you can test this approach on your local machine even without a remote server.

Just build your JAR, run it with these JVM options and connect with debugger.

Let’s do it on a simple example:

We can run it through the terminal


The Listening for transport dt_socket at address: 1045 message means that our application listens on port 1045 and waits for debugger to connect.

We can create a new Remote debug configuration in the IntelliJ IDEA.

Debug configuration

Now we can run our debugger and it’ll attach to the remote process!

Remote debug

The debugging process wilk work on the same way with the remote machine!

Let’s run it remotely

We’ll need a remote server or at least some system installed on VirtualBox. For the simplicity we can use the VirtualBox with installed Ubuntu server.

First of all we need to open the ports required for SSH and debugging.

Network settings
Port forwarding

As a code for demo we’ll use very simple code:

1public class DebugDemo {
3 public static void main(String[] args) {
4 System.out.println(debugMe(5));
5 System.out.println(debugMe(20));
6 }
8 private static int debugMe(int number) {
9 int multiplication = number * 15;
10 return multiplication / 3;
11 }

Let’s build the project and copy the JAR to out “remote” server:

1gradle clean jar
2scp build/libs/DebugDemo-1.0-SNAPSHOT.jar sergeioff@

Now we can run the JAR with our magical JVM options and we’ll see the same result

VirtualBox debug

We can connect with our favorite debugger and debug it!

Join my email list and get notified about new content

Be the first to receive my latest content with the ability to opt-out at anytime. I promise not to spam your inbox or share your email with any third parties.

More articles from Pogorelovs

Playing with MSK kafka

When you work with MSK you might want to connect with local producer/consumer to it for the test purposes, but you should keep in mind that MSK (as all AWS services) requires connection through SSL and here you'll need to specify it in your Kafka client...

February 4th, 2020 · 1 min read

Simple local Nginx

It's preety simple to run a local Nginx web server for test purposes...

February 4th, 2020 · 1 min read
© 2018–2020 Pogorelovs
Link to $https://github.com/sergeioffLink to $https://www.linkedin.com/in/sergeioff