31

I have an application that I deployed in tomcat. Later I configured the code as a project in Eclipse. I want to connect to the tomcat via eclipse and debug the application. Trying to setup a remote debug connection is throwing up errors. Is there any entry that I need to add somewhere in tomcat?

8 Answers 8

47

First, you need to run Tomcat in debugging mode. The easiest way to do that is to modify the startup file (.bat or .sh depending if you are Windows or not). Find the line near or at the end of the file that contains the start command, and change it to jpda start. This will cause Tomcat to start in debugging mode listening on port 8000.

Next, to connect to this process via Eclipse, select the Run menu and choose Debug Configurations.... In the pane on the left, choose Remote Java Application and click the New launch configuration button above the list. The important settings to note are the Host and Port fields. The host value must match the hostname of the Tomcat process, and the port should be 8000. You also might need to add entries on the Source tab to ensure that all of the source code is available to step through.

Sign up to request clarification or add additional context in comments.

5 Comments

Laz, I did all of this. But am still ending up with the error saying "Failed to connect to remote VM. Connection refused." Any idea why this error comes up?
Sounds like Tomcat isn't listening for whatever reason. Which file did you end up modifying?
Finally got it working. I added the JVM OPTS explicitly and gave a port other than the default 8000. Was able to get the debug connection working that way. Thanks for the help Laz!
@user811433 How did you add JVM OPTS ? Can you just post your startup.bat in which you added JVM OPTS?
Finally it worked. Port for debugging is different from connector port for your app. For some reason I thought that the port had to be 8080 or whatever it is that you are using instead of 8000.
15
  1. Create a new tomcat server

Create a new tomcat server

Tomcat version selection

Tomcat path and JRE version selection

Tomcat server is created successfully

  1. Create a new dynamic web project

Create a new dynamic web project

Export war to tomcat server

Export war to tomcat server

  1. Tomcat debug configuration(important), first double click tomcat server, then select "Use Tomcat installation (takes control of Tomcat installation)"

Tomcat debug configuration -- important!

  1. Add breakpoints

Add breakpoints

  1. Run tomcat in debug mode

Run tomcat in debug mode

  1. Test war in web browser

Test war in web browser

  1. Edit source path

Edit source path -- step 1

Edit source path -- step 2

  1. Debug source code in Tomcat

Debug source code in Tomcat

The war file is available here.

1 Comment

This is a super useful answer, just not to this question. I learned something, but not the answer to this problem
3

Simply change the line in startup.bat (if you are using Windows)

from:

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

to:

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Comments

3

yes, you need to configure tomcat to accept remote debugging connections. There is a FAQ on how to do it with various IDEs.

https://cwiki.apache.org/confluence/display/TOMCAT/Developing#Developing-Q1

1 Comment

Thanks for the link. I added the settings and tomcat on startup days "Listening for transport dt_socket at address: 8000". After this I tried Remote debugging from eclipse and it again fails with the same error "Failed to connect to remote VM. Connection refused."
2
  1. Right Click on the project you want to debug and go to Debug As Menu and in the list click on Debug Configurations.

Step 1. Image Description

  1. Then Double click on the Remote Java Application from left menu list. browse for the project u wanna add in then click apply.

    • Also change the listening port to 7999, then after you started the web app from your localhost click the debug button on the same window. Then any break point's will be hit after that.

Step 2. Image Description

Comments

1

Debug worked for me. I was using tomcat 8, configured on centos 7. Debug port opened for me after changing 2 settings.

  1. Open tomcat/conf/bin/startup.sh and added below lines
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
  1. In the same file startup.sh, added jpda before start command.
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"

Restart the tomcat. In eclipse go to Run>Debug configuration>Remote java application>Add host ip and port(8000) where tomcat is running. In my case i required to open 8000 through firewall too.

firewall-cmd --zone=public --permanent --add-port=8000/tcp
firewall-cmd --reload

Comments

0

Steps to setup the tomcat Debugger with eclipse

Install the following things:

java 1.8+

eclipse EE version

download tomcat 8+

open eclipse and go to servers tab and add a new server(window-> show View-> Others -> Search Servers)

Mark your project as Dynamic web Project(Rightclick on Project-> project facets -> select Dynamic web module)

Export war (File-> Export-> search war -> select module and choose the path)

Run as -> Run on Server

Start the tomcat Server in Debug or Run Mode

check on localhost:8080

Comments

0

Beside remote debugging, you can debug your app locally within eclipse if you added tomcat in eclipse. just start server and wright click your app and from debug menu hit debug on server. If you have multi module maven project, debug on server just shown up for module with war packaging. If you want debug a class that runs at startup by self, like methods that annotated with @PostConstruct, remember that you should increase server timeout. To do that, go to server view and double click on tomcat and in server preview tab, increase the timeout value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.