I can't seem to debug the tomcat application through Eclipse. I've set
CATALINA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
and then I run bin/catalina.sh
, where I see output saying it's listening for dt_socket
on port 8000
. But whenever I try to connect to port 8000
in Eclipse (by adding an entry in the remote java application menu), it complains about a refused connect. Any ideas?
Can you check if this works?
JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
catalina.sh jpda start
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
Configurations to be added for enabling remote debugging with in tomcat is
-Xdebug
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
I don't recommend above configuration fro non windows environment. To add the above configuration double click on tomcat server which will be available in server view. Find the below screen shot.
Now add the above runtime environment configuration to tomcat. For this check below screenshot.
Now got to Arugments tab in Edit launch configuration properties as show in below screen shot.
GoTo VM arguments section add these lines.
-Xdebug
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
Now got to debug button available on eclipse toolbar.
In Debug configurations find "Remote Java Application" and double click on it.
In Name field enter any name which you like to.
From project field using browse button select the project which you want to perform remote debug.
The hostname is nothing but the host address. Here i'm working locally so it is "localhost".
Last the Port column the value should be 8000. Apart from Name and Project text fields other two columns Host and port will be filled by eclipse itself if not make you have same values as mentioned. Check Screen shot for info.
Now right click on TomcatServer in server console select Add and Remove from context menu. From this dialog you can add the project to server.
Now run the Tomcat sever.
Now run the TomCatDebugConfiguration from Debug Tool.
Last open internal or external browser and run your project. If the execution control reached the break points then the eclipse will prompt for debug perspective.
In the tomcat bin directory where catalina.bat
or .sh
is found (aka {CATALINA_BASE}/bin), 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"
That's all you need to do, you don't need to edit the catalina.bat
(or .sh
) file.
See the comments in catalina.bat
or catalina.sh
.
You may have to adjust the syntax for your particular environment/situation. For example, if you already have CATALINA_OPTS defined, you might do something like this (in a windows environment):
set CATALINA_OPTS=%CATALINA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8088,server=y,suspend=n
To debug from Eclipse:
run->Debug configurations...->Remote Java Application->New
and specify a name, the project you are debugging, and the tomcat host and debug port specified above.
In catalina.bat
file please modify the 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: Run Tomcat from command prompt like below: catalina.sh jpda start
Step 4: Then in the eclipse create a debug configuration
project name
.Standard(Socket Attach)
localhost
8000
( or any port number , but that should be same in other places also).Many of the above answers are correct, but remember that by default the debugger will listen on localhost , which means you can debug only if you're running the debugging client (for example, the IDE) on the same machine.
If you are debugging a remote server you will need to specify the correct IP address on that server to listen on, 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 being used, by running
netstat -an
This command is valid on both windows and Linux - you just need to filter out the port with find
(Windows) or grep
(Linux).
Just run ./catalina.sh jpda start
(forks) or ./catalina.sh jpda run
(does not fork, not mentioned in help). All options mentioned here default to sane values.
Let me share the simple way to enable the remote debugging mode in tomcat7 with eclipse (Windows).
Step 1: open bin/startup.bat file
Step 2: add the below lines for debugging with JDPA option (it should starting line of the file )
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
Step 3: in the same file .. go to end of the file modify 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 ran in remote mode with port 8000).
step 5: after that lets connect your source project by eclipse IDE with remote client.
step6: In the Eclipse IDE go to "debug Configuration"
step7:click "remote java application" and on that click "New"
step8. in 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.
so finally your eclipse remote client is connected with the running tomcat server (debug mode).
Hope this approach might be help you.
Regards..
Modify catalina.bat 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 below line to run the debug mode by default when you run startup.bat
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Eclipse or STS select debug configuration right click -> new
connection type -> Standard socket Attach
Port -> 8000 (as given in the CATALINA_OPTS)
Host -> localhost or IP address
如果以上所有方法仍然无效,您可以随时添加到脚本中
set "JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
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 setup 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
Regards
For apache-tomcat-8.5.28 version just do this,
catalina.bat jpda start
As the default settings 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 need of any other config. And when you execute command catalina.bat jpda start, you can see debug port 8000 is opened.
I was hitting this issue while running Tomcat inside of a Docker container. To fix this make sure you add the '-p 8000:8000' argument in your docker run command to expose this port to your local machine. You will of course need the setenv.sh file in your ${CATALINA_HOME}/bin/ within your container as well.
Modifying the startup.bat with the CATALINA_OPTS AND JPDA_OPTS didn't work for me but adding them to catalina.bat did
CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
change call "%EXECUTABLE%" start %CMD_LINE_ARGS% to
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Then configure remote java application in your debug configurations in Eclipse.
First of all, if you open catalina.bat with text editor, you see that: "Do not set the variables in this script....." So never change it in that script, instead you can do below steps:
Then set 2 variables in that bat file such as:
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"
Lastly run that at cmd that: "catalina.bat jpda start"
In IDE, create remote debug configuration and set host to related server ip and port to 8000.
See this answer for issues I had with Java 8 and Tomcat 9: Java remote debugging (JPDA) not working for me in Tomcat 9
This is similar to @DAB's warning, and his solution is likely more secure.
For apache-tomcat-8.5.28
modify JDPA_OPTS
like the 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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.