Tomcat Remote Debugging Eclipse

When you use eclipse to develop a web application and deploy it into a remote tomcat server, how to debug the remote deployed web application to fix bugs? This article will tell you how to do it. This example will use Spring Tool Suite ( based on eclipse ) and tomcat server version 9.

1. Start Tomcat In Remote Debug Mode.

First, you need to start the tomcat server in JPDA mode, this mode can make the tomcat server remotely connected from an eclipse project. Below are the steps.

  1. CD into TOMCAT_HOME/bin folder in a terminal window.
  2. Run su to change to root user in Linux or macOS.
  3. Run ps -ef|grep tomcat to see whether the tomcat server is running or not.
  4. If tomcat is running, run shutdown.sh to stop it.
  5. Run catalina.sh jpda run command to start the tomcat server in debug mode.
  6. When you see the output in the terminal window like the below message, it means the tomcat server has been started in debug mode successfully, it listens on port 8000.
    Listening for transport dt_socket at address: 8000
    .................................
    Server startup in *** ms

2. Debug Java Web Application From Eclipse Remotely.

After deploying your java web application in the tomcat server, you can now debug the code from eclipse remotely.

  1. Click Run —> Debug Configurations… menu item in the eclipse top menu bar to open the Create, manage, and run configurations dialog window.
  2. Select the Remote Java Application item in the left panel. It will show the text Attach to a Java virtual machine accepting debug connections under the dialog title.
  3. Then click the add icon( eclipse-configuration-new-item-icon ) on the left panel top left corner to add a new configuration.
  4. Input the configuration name in the Name input textbox ( SpringMVCXmlBased_RemoteDebug in this example ).
  5. Browse to select the current java project in the Project text box.
  6. Select Standard ( Socket Attach ) from the Connection Type: drop-down list.
  7. Input correct Connection Properties: Host (  the remote tomcat server IP address, in this example it is localhost because the tomcat server running on the same machine with the eclipse ) and Port ( the remote tomcat server listening port number, in this example it is 8000 ).
    add-a-new-remote-java-application-debug-configuration
  8. Then click Apply button to save the settings. Click Debug button to begin to debug project code with the web application deployed in the remote tomcat server. You can set breakpoints in your project source code, when the application runs into the breakpoint, the execution will be paused, then you can watch the values of the variables that you want.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.