Remote Debugging with IntelliJ

Sometimes it’s not possible to debug your code locally in your IDE of choice, sometimes you will need to debug remotely but how do you go about it?

Assuming that you’re using IntelliJ (Eclipse is not that different incidentally) then here’s how;

  1. Go to Run > Edit Configurations.
  2. From the menu click + for a new configuration and select ‘Remote’.
  3. You will be faced with this window;

    Change the host to the machine that your Java application is running on.
    Change the port to be something that you can access and is not already in use.
    Give the debug configuration a memorable name.
    Make sure you select the right source for “Search sources using module’s classpath”
    Click the copy icon next to the appropriate JVM version. Save the debug args somewhere, we will need them!

  4. Now you need to change your application so that when it’s started it contains the arguments that IntelliJ gave you. So for example;
    java myapp
    java myapp -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
  5. With your application running hit debug!

A couple of important points;

  • If your local source code differs from what’s running on the remote server then you will see the debugger do some strange things, for example going in to what look to be empty lines.
  • If you want your application to wait for you to attach a debugger before starting just change “suspend=n” to “suspend=y”.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s