Friday, April 17, 2009

Remote debugging using IntelliJ

I had few stand alone java processes running that are not started from the IDE which I had to debug from IntelliJ, it took quite some time for me to figure out how to do that, so I thought will blog it for people who might need it.

It’s quite simple all you have to do is, run the java process which ever you want to debug using the following flags for java command.

$ java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9995 RemoteProcess

Where:

9995 is the port on which the IntelliJ will hook on to your remote java process for debugging information. This can be any port as long is it is not being used by other process.

RemoteProcess is a stand alone java process which you want to debug.

Once the java process is up and running, here is what you need to do in IntelliJ to start debugging that process.

Make sure you have the code base of the java process you are running opened in the IDE, go to Run -> Edit Configurations which opens up the config window as shown below.


Click on the + symbol on the top left corner of the window, which prompts you to select one of the different available configurations, select Remote from the given list as shown in the picture below.


It adds a new remote configuration and the config window is defaulted with few values as shown in the picture below.


Fill in the window with the values as described below.

Name text field: Enter the remote process name (can be any string, its just an identifier for your remote process)

Following values are for the settings section.

Transport: Select "Socket" option.

Debugger Mode: Select "Attach" option.

Host: Enter the hostname or IP address of the host on which the remote java process is running, if the java process is running on the same machine as of IntelliJ, you can just fill in as "localhost" as the value for this field.

Port: Enter the same port which your have used in the debugging flags while starting the remote java process. In this particular example it is 9995.

Click on Apply button and save the configuration.

That's it you are ready to debug your remote java process.

To start the debugging session, go to Run -> Debug, from the left pane select the configuration you just savedin the previous step and hit the Debug button. IntelliJ starts the debugging session immediately.



1 comment:

Hari said...

Thanks katta! i am coming to this page again and again.. :)