Remote debugging with Tomcat (7) and Intellij

It took me a while to find out how to set up Tomcat 7 to allow for remote debugging from Intellij, so I decided to put the process up here for my own future reference and hopefully for other people's convenience. This small tutorial is aimed at Windows users, but it shouldn't be too difficult to figure out how to do it on Linux.

Configuring Tomcat 7

Follow these steps to configure Tomcat.

  1. Go to your Tomcat installation directory and then into the bin folder.
  2. Create a new file called setenv.bat. (This file will be automatically read by catalina.bat)
  3. Add the following content to setenv.bat:

    set CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"

    I chose the default port number for remote debugging, which is 8000, but you can choose any port number you like.
  4. Now start Tomcat normally, using startup.bat. The first thing Tomcat should tell you is that it is listening on port 8000.

    Tomcat listening for debugging

Now that Tomcat is ready for debugging let's see how to create a debugging configuration in Eclipse and Intellij.

Remote debugging configuration in IntelliJ

Follow these steps to configure remote debugging of Tomcat in Intellij.

  1. Open the Run/Debug configurations window by clicking the dropdown in the middle of the main toolbar or by going to Run > Edit configurations.

    Edit configurations in Intellij 
  2. In the Run/Debug configurations window click the small yellowy/orangy + icon in the upper left corner and select Remote from the list of choices that appears.
  3. In your new Remote debugging conif fill out the Name and Port and optionally the Module from the Module dropdown. 

    You can make up a Name yourself.
    The Port must match the port number you provided in the CATALINA_OPTS earlier.
    The Module selection is optional, of you want to debug a specific module only.

    Remote debug configuration
  4. Now click OK.
  5. When Tomcat is started and your application is running you can now start debugging by selecting your debug configuration in the Intellij toolbar and pressing the green debug icon next to it.

    Debugging in intellij

garaki at Friday, September 7, 2012 4:15 PM hi, thanks a lot.. it worked

George at Saturday, May 25, 2013 4:25 AM Thanks for the post. It helped me figure this out real quick. Two notes: 1. Make sure CATALINA_HOME points to the correct Tomcat - I had Tomcat 6 installed as well and did not re-point my environment variable initially. 2. Do not put thefolling in your catalina.bat if you followed the instructions for this tutorial (you can use either one or the other method but not both) CATALINA_OPTS=set CATALINA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

Bogdan at Friday, May 31, 2013 11:31 AM very good post. helped me a lot. thanks

Thiwanka at Wednesday, June 11, 2014 9:48 AM Can you post a blog by explaining how debug web project (jsp/servelet project) remotly using intelij idea

subba at Thursday, November 13, 2014 7:56 PM thanks it works

subba at Thursday, November 13, 2014 8:00 PM thanks it works

Ken at Wednesday, October 18, 2017 5:25 PM Perfect !!! Thanks.

Your email address will not be shown on the site
7 x 4 =