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 remote connected from a eclipse project.
- CD into TOMCAT_HOME/bin folder in a terminal window.
- Run
su
to change to root user in Linux or MacOS. - Run
ps -ef|grep tomcat
to see whether the tomcat server is running or not. - If tomcat is running, run
shutdown.sh
to stop it. - Run
catalina.sh jpda run
command to start tomcat server in debug mode. - When you see output in the terminal window like below message, it means 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.
After deploy your java web application in tomcat server, you can now debug the code from eclipse.
- Click Run —> Debug Configurations… menu item in the eclipse top menu bar.
- Select Remote Java Application item in left panel. Then click add icon
at top left to add a new configuration, and input correct connection properties such as Host ( localhost ) and Port ( 8000 ).
- Then click Apply button to save the settings. Click Debug button to begin debug project code with the web application deployed in the remote tomcat server. You can set breakpoint in your project source code, when application run into the breakpoint, the execution will be paused, then you can watch the variables values.