Sunday, May 8, 2016

Remote debugging Tomcat with Eclipse

Sometimes it is required to debug a remote  application that is deployed in tomcat in the local network.We can configure eclipse to  debug the remote application locally  for a running tomcat instance that is configured with JPDA support.JPDA is a multi-tiered debugging architecture.Please visit the oracle docs for more about JPDA.

First let's set up tomcat for remote debugging using JPDA

Setting Up Tomcat For Remote Debugging

 Tomcat can be configured to allow a program such as eclipse to connect remotely using JPDA and see debugging information.We can do the configuration change in catalina.sh.Now open the catalina.sh or catalina.bat and find the line JPDA_TRANSPORT.Chnage the value of the parameter as  

JPDA_TRANSPORT=dt_socket
JPDA_ADDRESS="ipwhereyourapplicationisdeployed:5001" (port 5001 is not mandatory, you can give any unused port)

Here also we can write  JPDA_ADDRESS="*:5001" ,but it has some security issue,so it is good practice to specify the ip.

Then we start tomcat with the command ./catalina.sh jpda run.And now we are ready to go.

Also without changing anything in catalina.sh or catalina.bat , we can write the same parameter in startup.sh or startup.bat  

In Unix
export JPDA_ADDRESS=ip:5001
export JPDA_TRANSPORT=dt_socket
bin/catalina.sh jpda run
In Windows
set JPDA_ADDRESS=ip:5001
set JPDA_TRANSPORT=dt_socket
bin/catalina.bat jpda start
 Once we  have tomcat configured , now we start tomcat manually from command line.


Now we configure our eclipse to listen the tomcat running remotely.

Setting Up Eclipse:

1.Set break point in eclipse.
2.Then Debug As Debug Configurations...
3.Then double click on the heading Remote Java Application.A window like this will appear

4.In the host write the ip address you mentioned in the JPDA_ADRESS and in port write the port you mentioned in JPDA_ADDRESS.Here in our case it is 5001.
5.Now click apply and debug.

Now the  eclipse is ready for debugging.

The above scenario is tested in  Linux Mint 17.1 Rebecca ,STS 3.7.2 and apache-tomcat-8.0.24.