Tomcat remote debugging with Eclipse

I cannot debug tomcat application through Eclipse. I have installed

CATALINA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

and then I ran bin/catalina.sh , where I see the output saying that it is listening on dt_socket on port 8000 . But whenever I try to connect to port 8000 in Eclipse (by adding an entry to the menu of the remote java application), it complains about the connection being refused. Any ideas?

+81
eclipse tomcat
30 Sep '10 at 23:49
source share
16 answers

Can you check if this works?

 JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n" catalina.sh jpda start 
+117
01 Oct '10 at 6:02
source share

I spent some time on this to get the right information.

So, here is the detailed information step by step.

Environment: Windows 7

TomCat Version: 7.0

IDE: Eclipse

The configurations you need to add to enable remote debugging in tomcat is

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

I do not recommend this configuration for a windowless environment. To add the above configuration, double-click on the tomcat server, which will be available on the server. Find the screenshot below. enter image description here

Now add the above runtime configuration to tomcat. For this check a screenshot.

enter image description here

Now go to the "Remixes" tab in the "Launch Editing Launch Properties" section, as shown below.

enter image description here

The GoTo VM argument section adds these lines.

-Xdebug

-agentlib: JDWP = = transport socket transport, address = 8000, server = y, pause = n

enter image description here

Now there is a debug button available on the eclipse toolbar.

enter image description here

In the Debug configurations, find "Remote Java Application" and double-click on it. enter image description here

In the Name box, enter any name you like.

From the project field, use the browse button to select the project that you want to perform remote debugging.

The host name is only the host address. Here I work locally, so this is "localhost".

In the last column of Port, the value should be 8000. In addition to the Name and Project text boxes, the other two Host and port columns will be filled by eclipse itself if you do not specify the same values โ€‹โ€‹as those mentioned. Check out the screenshot for information. enter image description here

Now right-click on TomcatServer in the server console, select "Add and Remove from the context menu." In this dialog box, you can add the project to the server.

Now run Tomcat sever.

enter image description here

Now run TomCatDebugConfiguration from the Debug tool.

The last open internal or external browser and launch of your project. If the execution control has reached break points, then the eclipse will ask for debugging prospects.

+47
Jul 03 '15 at 12:30
source share

In the tomcat bin directory where catalina.bat or .sh (aka {CATALINA_BASE} / bin) are found, edit (create, if not there):

 setenv.bat/.sh 

Add the following line:

 CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" 

For all you need to do, you do not need to edit the catalina.bat (or .sh ) file.

See comments in catalina.bat or catalina.sh .

You may need to adjust the syntax for a specific environment / situation. For example, if you already have CATALINA_OPTS defined, you can do something like this (on a Windows environment):

 set CATALINA_OPTS=%CATALINA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8088,server=y,suspend=n 

Debugging with Eclipse:

run-> Debug Configurations ...-> Remote Java Application-> New

and specify the name, the project you are debugging, and the tomcat host and debug port specified above.

+44
Apr 6 '13 at
source share

In the catalina.bat file, please change below.

  • Step 1: CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

  • Step 2: JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"

  • Step 3. Start Tomcat from the command line, like catalina.sh jpda start below: catalina.sh jpda start

  • Step 4: Then in eclipse create a debug configuration

    1. Give a name for the configuration.
    2. Specify project name .
    3. Specify the connection type as Standard(Socket Attach)
    4. host as localhost
    5. a port like 8000 (or any port number, but it should be the same in other places).
+29
Nov 22 '12 at 17:32
source share

Let me share a simple way to enable remote debugging mode in tomcat7 using eclipse (Windows).

Step 1: open the bin / startup.bat file
Step 2: add below line for debugging with JDPA option (it should start with line)

  set JPDA_ADDRESS=8000 set JPDA_TRANSPORT=dt_socket 

Step 3: in the same file .. go to the end of the file change this line -

  call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS% instead of line call "%EXECUTABLE%" start %CMD_LINE_ARGS% 

step 4: then just run bin> startup.bat (so now your tomcat server was working remotely with port 8000).

Step 5: After that, you can connect the source project using the eclipse IDE with the remote client.

step6: In the Eclipse IDE, go to the "Debug Configuration" section

step7: click "remote Java application" and click "New"

step8. on the "connect" tab, set the parameter value

  project= your source project connection Type: standard (socket attached) host: localhost port:8000 

step9: click apply and debug.

finally, your remote eclipse client will be connected to a running tomcat server (debug mode).

Hope this approach can help you.

Respectfully..

+5
03 Feb '16 at 12:29
source share

Change the catalina.bat parameter to add

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

and

 CATALINA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n 

Optional: add the line below to start default debugging mode at startup.bat

 call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS% 

Eclipse or STS select right-click debug configuration -> new

 connection type -> Standard socket Attach Port -> 8000 (as given in the CATALINA_OPTS) Host -> localhost or IP address 
+4
Aug 19 '14 at 9:31
source share

Just run ./catalina.sh jpda start (forks) or ./catalina.sh jpda run (not fork, not mentioned in the help). All parameters mentioned here default to normal values.

+4
Jul 29 '15 at 8:35
source share

If all of the above does not work, you can always add to the script

  set "JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" 
+2
Nov 15 '13 at 6:06
source share

In tomcat 7, catalina.sh has this code:

 if [ "$1" = "jpda" ] ; then if [ -z "$JPDA_TRANSPORT" ]; then JPDA_TRANSPORT="dt_socket" fi if [ -z "$JPDA_ADDRESS" ]; then JPDA_ADDRESS="8000" fi if [ -z "$JPDA_SUSPEND" ]; then JPDA_SUSPEND="n" fi if [ -z "$JPDA_OPTS" ]; then JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND" fi CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS" shift fi 

Ii implies that you can configure JPDA with:

 export JPDA_TRANSPORT=dt_socket export JPDA_ADDRESS=8000 export JPDA_SUSPEND=n 

Or with:

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

And finally use:

catalina.sh jpda start

Hello

+1
Apr 15 '15 at 13:49
source share

I encountered this problem while running Tomcat inside a Docker container. To fix this, make sure you add the -p 8000: 8000 'argument to the docker launch command to open this port on your local computer. Of course, you will need the setenv.sh file in your $ {CATALINA_HOME} / bin / in your container.

+1
Jun 15 '18 at 18:22
source share

Many of the answers above are correct, but remember that by default the debugger will only listen on the local host. If you are debugging a remote server, you need to specify the IP address for listening, for example

JPDA_OPTS = "-agentlib: jdwp = transport = dt_socket, address = 10.1.1.33 : 8000, server = y, suspend = n"

catalina.sh jpda start

Note that the address is now 10.1.1.33 : 8000

Of course, you can also check which IP is actually used by running

netstat -an

on Windows and Linux and filter the port using the find (Win) or grep (Linux) command.

+1
Jan 9 '19 at 10:44
source share

Modifying startup.bat with CATALINA_OPTS and JPDA_OPTS did not work for me, but added them to catalina.bat.

  • Edit Catalina.bat

CATALINA_OPTS = "- Xdebug -Xrunjdwp: transport = dt_socket, address = 8000, server = y, suspend = n"

JPDA_OPTS = "- agentlib: JDWP = transport = transport on sockets, address = 8000, server = y, suspend = n"

  1. Change startup.bat to enable jpda

change call "% EXECUTABLE%" start% CMD_LINE_ARGS% to

call "% EXECUTABLE%" jpda start% CMD_LINE_ARGS%

Then configure the remote java application in your debug configurations in Eclipse.

0
Sep 15 '16 at 17:49
source share

First of all, if you open the catalina.bat file with a text editor, you will see the following: "Do not set the variables in this script ....." Therefore, never modify it in this script, instead you can take the following steps:

  • He advises you to create a new bat file named "setenv.bat".
  • Then set 2 variables in the bat file, for example:

    set CATALINA_OPTS = "- Xdebug -Xrunjdwp: transport = dt_socket, address = 8000, server = y, suspend = n"

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

  • Finally, run on cmd that: "catalina.bat jpda start"

  • In the IDE, create a remote debug configuration and set the appropriate ip and server port to 8000 for the host.

0
Dec 12 '16 at 11:02
source share

For apache-tomcat-8.5.28 version, just do it,

 catalina.bat jpda start 

Since the default settings are already configured for us in catalina.bat as

if not "% JPDA_OPTS%" == "" goto gotJpdaOpts set JPDA_OPTS = -agentlib: jdwp = transport =% JPDA_TRANSPORT%, address =% JPDA_ADDRESS%, server = y, suspend =% JPDA_SUSPEND%

So no other configuration is needed. And when you run the catalina.bat jpda start command, you can see the debug port 8000.

0
Mar 14 '18 at 0:20
source share

See this answer for the problems I had with Java 8 and Tomcat 9: Java Remote Debugging (JPDA) does not work for me in Tomcat 9

This is similar to the @DAB warning, and its solution is probably more secure.

0
May 08 '19 at 14:51
source share

For apache-tomcat-8.5.28

change JDPA_OPTS as JDPA_OPTS below then run like catalina.bat jpda start

 JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND" JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=8000,server=y,suspend=$JPDA_SUSPEND" 
-2
Mar 15 '18 at 13:06
source share



All Articles