First step would be to configure Tomcat to support remote debugging. Now in order to do that we need to add the following command line arguments in cataline.bat (add these JVM options before any other JVM options):
If we are using shell scripts to start Tomcat then we need to start it with the jpda command like this:
Note : jpda (Java Platform Debugger Architecture) is a collection of APIs to debug Java code.
catalina jpda start
For jpda we need to set the following env variables:
JPDA_TRANSPORT : (Optional) JPDA transport used when the "jpda start" command is executed. The default is "dt_shmem".
JPDA_ADDRESS : (Optional) Java runtime options used when the "jpda start" command is executed. The default is "jdbconn".
JPDA transport implementation can be set to dt_socket : JPDA_TRANSPORT=dt_socket
Port number can be set to 8000 or any other appropriate value : JPDA_ADDRESS=8000
Next step would be to configure Eclipse to debug tomcat remotely:
Start tomcat in remote debugging mode.
Set a breakpoint somewhere in your code.
Under the "Run" menu, select "Debug Configurations". Refer screenshot 1:
Go to "Remote Java Application" and click "New" (or simply double click on the Remote Java Application). Refer screenshot 2:
On the dialog that appears, enter a meaningful name for this configuration. Select appropriate project from your workspace. Enter connection properties : Host and Port.Click "Apply" to save your changes. Click "Debug" to start testing your configuration. Refer screenshot 3:
Now start sending requests to your application and you will reach your breakpoint. You should be directed into Eclipse where you will see the line of code with your breakpoint.