【转】Remote debugging of Tomcat using Eclipse

This post shows how to debug an application deployed in Apache Tomcat remotely (Tomcat is a popular Servlet container). This is valid for any other application server or any other Java application since the debug in remote is a feature of the JVM (Java Virtual Machine) over which any Java application is run.

For debugging a Java application remotely with Eclipse we need three things:

  1. Run the application indicating to the JVM that it has to be executed in debug mode.
  2. The source code of the application we want to debug.
  3. Configure Eclipse to debug the application.

 

Starting Apache Tomcat in debug mode

First of all we have to restart the Tomcat with debug option for this purpose we need to pass to JVM (Java Virtual Machine) the options

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

JVM opens a port in current machine allowing external applications (like Eclipse) to connect for debugging purposes.

To do that with Tomcat we have to set the environment variable JAVA_OPTS that is read by Tomcat in startup.sh file.

1) Set variable and make it available. we can choose the port number, in this example is used 8000 number.

1
export JAVA_OPTS= "-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

2) Start Tomcat (from bin folder):

1
. /startup .sh

 

 

Configuring Eclipse to remote debugging

First of all, we have to open or import the project with the source code of the application we want to debug. Afterward we have to setup the debug from Eclipse:

1) Clicking on the right side (arrow facing to above) of the “Debug” button (the button with the bug) that is in the toolbar and the clicking on “Debug configurations…” or in the menu Run > Debug configurations… Then a new window with the different debug configuration will be opened.

Debug configuration

2) Select “Remote Java Application” in the left menu and then press on “New launch configuration” button (the button with the folder icon in the top-left corner).

New debug configuration

3) Fill the configuration with the data corresponding with our Tomcat instance:

  • Project: The project we want to debug: it has to contain the source code for the application we want to debug.
  • Connection Type: Standard (Socket Attach).
  • Host: IP of the server in which is Tomcat installed.
  • Port: Port indicated to JVM in address parameter. Port 8000 in our example
Debug configuration sample data

Remote Debugging of Tomcat with Eclipse

4) Execute the debug. We have to click on the button “Debug” and Eclipse will connect with Tomcat (it had to be previously running as I mentioned in this post). Now we have to put the breakpoints inside the Eclipse project to debug as we do with a regular project running in a local Tomcat.

And that’s all, if everything works well you can debug your Tomcat remotely. Now there is a long work to do debugging your app. Good luck!

 

from:http://davidsblog.eu/remote-debugging-of-tomcat-using-eclipse/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值