Remote Debugging in IntelliJ Tomcat

Intellij Idea

Intellij Idea Problem Overview


How to enable remote debugging from IntelliJ with Tomcat?

Intellij Idea Solutions


Solution 1 - Intellij Idea

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 - Intellij Idea

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 - Intellij Idea

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 - Intellij Idea

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 - Intellij Idea

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

Solution 6 - Intellij Idea

In Intellij Idea:

  1. Click on Run -> Edit Configurations -> Add New Configurations ("+" icon)

  2. Click on Remote

  3. Set Host and Port

  4. Copy content of Command line arguments for running remote JVM, for example:

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

enter image description here

If you use Tomcat Service (for Tomcat 9):

  1. Go to %TOMCAT_INSTALL_DIR%/bin

  2. Run tomcat9w.exe

  3. Click on Java tab

  4. In Java Options Paste the copied text:

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

  5. Apply.

enter image description here

Solution 7 - Intellij Idea

Add these two line to your bin/setenv.sh

export JPDA_ADDRESS="5005"
export JPDA_TRANSPORT="dt_socket"

Add remote Run/Debug Configuration in IntelliJ IDEA. (see the answer from @Jonathan L). You can keep the default port '5005'.

Start tomcat,

catalina.sh jpda run

Then simply run debug on the IDE.

Solution 8 - Intellij Idea

you can set

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

in setenv.sh file in bin tomcat directory (remote server) and restart it.

then just you should add Remote in Run/Debug Configurations in intellij and set Host to remote server and Port 8000

Solution 9 - Intellij Idea

Step1 (How to start tomcat):

cd /C/SOFTWARE/apache-tomcat-8.5.38/bin 
JAVA_OPTS='-agentlib:jdwp=transport=dt_socket,address=54470,suspend=n,server=y' sh catalina.sh start
ps aux | grep java

Step 2 ( Attach Intellij with remote port ):

Run/Debug Configurations
    Tab: Server:
       Application Server: Type "Tomcat 8.5.38"
       Open browser -> URL -> http://localhost:8080/
       Tomcat Server Settings -> Type -> Same File System
                              -> Host -> Same File System

       Remote Connection Settings
                           -> Host -> localhost
                           -> Port -> 8080

Startup/Connection Tab
       Run -> No specific parameters needed.
       Debug -> -agentlib:jdwp=transport=dt_socket,address=54470,suspend=n,server=y

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser729344View Question on Stackoverflow
Solution 1 - Intellij IdeaCrazyCoderView Answer on Stackoverflow
Solution 2 - Intellij IdeaJonathan LView Answer on Stackoverflow
Solution 3 - Intellij IdeaZaur_MView Answer on Stackoverflow
Solution 4 - Intellij IdeaFrançoisView Answer on Stackoverflow
Solution 5 - Intellij IdeaHachmaninowView Answer on Stackoverflow
Solution 6 - Intellij IdeaTaras MelnykView Answer on Stackoverflow
Solution 7 - Intellij IdeaGayan WeerakuttiView Answer on Stackoverflow
Solution 8 - Intellij IdeaAlireza AlallahView Answer on Stackoverflow
Solution 9 - Intellij Ideauser204069View Answer on Stackoverflow