Remote Debugging in IntelliJ Tomcat

How to enable remote debugging from IntelliJ with Tomcat?


Solution 1:

Use Tomcat Run/Debug Configuration. Click the enter image description here button and choose new Remote configuration. In the Configuration tab copy the JVM options suggested by IDEA.

Run Tomcat with the suggested JVM options:

set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=1317,suspend=n,server=y
startup

Press Debug button in IDEA.

Otherwise it's the same as for Local Tomcat, check the tutorial.

Note that deploying to Tomcat is available only in IDEA Ultimate, but you can still manually deploy to Tomcat on your own and use Java's remote debug features using the free edition.

Solution 2:

Assume you start Tomcat standalone and attach debugger remotely to it from IntelliJ IDE.

1) Start Tomcat in debug mode
   $TOMCAT_HOME/bin/catalina.sh jpda start

   By default JPDA_ADDRESS is defined as "localhost:8000" in catalina.sh
   Change to a different port as need

2) In IntelliJ IDE
   Click Run > Edit Configurations
   Click + icon on the top-left toolbar
   Click Remote
   Enter a name you want in Name input box
   Enter 8000 in Port input box under Settings section

3) Click Apply, then OK
4) Run > Debug..., Click the configuration you just created

Note:

1) This should work with other remote JPDA instances such as WebLogic, JBoss, etc.
2) Documentation environment: Linux, IntelliJ IDEA 15.0.2

IntelliJ Remote Debugger Configuration

Solution 3:

just start catalina using following command:

catalina jpda start

By default tomcat will start and listen on port 8000.

See also http://wiki.apache.org/tomcat/FAQ/Developing#Q1

Solution 4:

TOMCAT Configuration Instructions

The process of getting remote debugging working involves two steps.

 1. Starting Tomcat with remote debugging enabled
 2. Having your IDE, in my case IntelliJ IDEA, to be able to debug the remote tomcat application.

There are couple of ways to get the first part done and it slightly differs depending on which OS environment your Tomcat instance is running on. But, regardless of the method used, the main idea behind the configuration remains the same; which is: pass specific start up options to the JVM that would enable remote debugging.

If you have Tomcat running as a windows service, then configuring Tomcat to start up with ability to be debugged remotely is done by simply specifying the start up arguments in the run properties.

Open up the Apache Tomcat properties dialog box :

Apache Tomcat/bin/tomcat9w.exe

and under the Java tab add the required start up option:

-agentlib:jdwp=transport=dt_socket,address=1043,server=y,suspend=n

enter image description here

Restart your server now.    
Close and go to your IDE.

Configuring IntelliJ IDEA

With the remote JVM running the Tomcat started with the required start up arguments, the next thing to do is to configure the debugger in IntelliJ IDEA.

Open the Edit Configuration settings and select the Remote option:

The Remote settings dialog box appears where you can specify the required configuration; remote host, port, project, etc...

enter image description here

Specify the required settings, click Ok to save changes, and start the debugging session. You should also see the notice that IntelliJ has successfully connected to the remote VM.

Once this is done, you should then open the source code of the application you have running on the remote Tomcat, put a breakpoint where required and you can go ahead and start debugging as if the application is running on your local machine.

Solution 5:

Remote debugging of web applications running in Tomcat 7 is extremly convenient in IntelliJ IDEA 12 if you use Maven!

Just configure your pom-file to use the tomcat7-maven-plugin, eg:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
</plugin>

Then use the "Maven Projects" tool window to start the tomcat7:run goal in debug mode (see screenshot).

enter image description here