Java Remote Debug with Eclipse

Debugging a remotely running Java application using Eclipse IDE is an important skill in our Java debug arsenal. Eclipse IDE is what I use mostly and so I took it for example. Configuring the same for debug with other IDEs like NetBeans, IntelliJ should be similar.

We will need this remote debug mechanism when the application is running separately outside of IDE. Mostly when the application might be in different system in the network. We will have the source or project configured in IDE in our system. Scenarios include, issue coming only in some X system and application working good in other systems. In that case, we want to remotely debug the application running in that X system.

This is a how-to tutorial and if you know how to remote debug a Java application using Eclipse, please terminate reading this, you may not find anything interesting and finally you will blame me, saying you didn’t expect a so basic article from me. If you are looking for Eclipse debugging tips in general, you can refer to this earlier written super hit article.

To debug remote Java application

Step 1: Start the application in debugging mode

server=y – Java application should be a TCP/IP server and wait for connections

suspend=y – the Java application (now server) will pause on start up and wait for debugger to join. If ‘n‘, application will not wait for debugger at start up, instead it will run as usual and when IDE encounters breakpoint it will fork the application.

address=<debug-port> – a port number on which the debugger will join to debug the application. Remember, this should be a port that is not already in use.

ClassName – Java application main-class name. If we have a jar we can include that with appropriate classpath.

Step 2: Configure and Start Eclipse in Remote Debugging Mode

First we should have the project source in place. Keep the breakpoints wherever necessary.

Go to Run –> Debug Configurations –> Remote Java Application

Create ‘New’ remote java application and give the Host and Port. Host is the IP of the machine where the remote java application is running. If the application is running in the same machine, then we can give localhost. Then the port which we have given while starting the application in remote mode.