简体   繁体   中英

debugging java application deployed in tomcat

I have an application that I deployed in tomcat. Later I configured the code as a project in Eclipse. I want to connect to the tomcat via eclipse and debug the application. Trying to setup a remote debug connection is throwing up errors. Is there any entry that I need to add somewhere in tomcat?

First, you need to run Tomcat in debugging mode. The easiest way to do that is to modify the startup file (.bat or .sh depending if you are Windows or not). Find the line near or at the end of the file that contains the start command, and change it to jpda start . This will cause Tomcat to start in debugging mode listening on port 8000 .

Next, to connect to this process via Eclipse, select the Run menu and choose Debug Configurations... . In the pane on the left, choose Remote Java Application and click the New launch configuration button above the list. The important settings to note are the Host and Port fields. The host value must match the hostname of the Tomcat process, and the port should be 8000 . You also might need to add entries on the Source tab to ensure that all of the source code is available to step through.

  1. Create a new tomcat server

新建一个tomcat服务器

Tomcat版本选择

Tomcat路径和JRE版本选择

Tomcat服务器创建成功

  1. Create a new dynamic web project

创建一个新的动态 Web 项目

Export war to tomcat server

将war导出到tomcat服务器

  1. Tomcat debug configuration(important), first double click tomcat server, then select "Use Tomcat installation (takes control of Tomcat installation)"

Tomcat 调试配置——重要!

  1. Add breakpoints

添加断点

  1. Run tomcat in debug mode

在调试模式下运行 tomcat

  1. Test war in web browser

在网络浏览器中测试战争

  1. Edit source path

编辑源路径——步骤 1

编辑源路径——第 2 步

  1. Debug source code in Tomcat

在Tomcat中调试源代码

The war file is available here .

Simply change the line in startup.bat (if you are using Windows)

from:

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

to:

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

yes, you need to configure tomcat to accept remote debugging connections. There is a FAQ on how to do it with various IDEs.

http://wiki.apache.org/tomcat/FAQ/Developing#Q2

  1. Right Click on the project you want to debug and go to Debug As Menu and in the list click on Debug Configurations.

步骤 1. 图像描述

  1. Then Double click on the Remote Java Application from left menu list. browse for the project u wanna add in then click apply.

    • Also change the listening port to 7999, then after you started the web app from your localhost click the debug button on the same window. Then any break point's will be hit after that.

步骤 2. 图像描述

Steps to setup the tomcat Debugger with eclipse

Install the following things:

java 1.8+

eclipse EE version

download tomcat 8+

open eclipse and go to servers tab and add a new server(window-> show View-> Others -> Search Servers)

Mark your project as Dynamic web Project(Rightclick on Project-> project facets -> select Dynamic web module)

Export war (File-> Export-> search war -> select module and choose the path)

Run as -> Run on Server

Start the tomcat Server in Debug or Run Mode

check on localhost:8080

Debug worked for me. I was using tomcat 8, configured on centos 7. Debug port opened for me after changing 2 settings.

  1. Open tomcat/conf/bin/startup.sh and added below lines
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
  1. In the same file startup.sh, added before start command.
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"

Restart the tomcat. In eclipse go to where tomcat is running.运行 tomcat 的In my case i required to open 8000 through firewall too.

firewall-cmd --zone=public --permanent --add-port=8000/tcp
firewall-cmd --reload

Beside remote debugging, you can debug your app locally within eclipse if you added tomcat in eclipse. just start server and wright click your app and from debug menu hit debug on server. If you have multi module maven project, debug on server just shown up for module with war packaging. If you want debug a class that runs at startup by self, like methods that annotated with @PostConstruct, remember that you should increase server timeout. To do that, go to server view and double click on tomcat and in server preview tab, increase the timeout value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM