简体   繁体   English

调试部署在tomcat中的java应用

[英]debugging java application deployed in tomcat

I have an application that I deployed in tomcat.我有一个部署在 tomcat 中的应用程序。 Later I configured the code as a project in Eclipse.后来我在 Eclipse 中将代码配置为一个项目。 I want to connect to the tomcat via eclipse and debug the application.我想通过eclipse连接到tomcat并调试应用程序。 Trying to setup a remote debug connection is throwing up errors.尝试设置远程调试连接会引发错误。 Is there any entry that I need to add somewhere in tomcat?我需要在 tomcat 的某处添加任何条目吗?

First, you need to run Tomcat in debugging mode.首先,您需要在调试模式下运行Tomcat。 The easiest way to do that is to modify the startup file (.bat or .sh depending if you are Windows or not).最简单的方法是修改启动文件(.bat 或 .sh,具体取决于您是否使用 Windows)。 Find the line near or at the end of the file that contains the start command, and change it to jpda start .找到包含start命令的文件附近或末尾的行,并将其更改为jpda start This will cause Tomcat to start in debugging mode listening on port 8000 .这将导致 Tomcat 以调试模式启动,侦听端口8000

Next, to connect to this process via Eclipse, select the Run menu and choose Debug Configurations... .接下来,要通过 Eclipse 连接到此进程,请选择Run菜单并选择Debug Configurations... In the pane on the left, choose Remote Java Application and click the New launch configuration button above the list.在左侧窗格中,选择Remote Java Application并单击列表上方的New launch configuration按钮。 The important settings to note are the Host and Port fields.需要注意的重要设置是HostPort字段。 The host value must match the hostname of the Tomcat process, and the port should be 8000 .主机值必须与 Tomcat 进程的主机名匹配,端口应为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.您可能还需要在Source选项卡上添加条目以确保所有源代码都可用于单步执行。

  1. Create a new tomcat server新建一个tomcat服务器

新建一个tomcat服务器

Tomcat版本选择

Tomcat路径和JRE版本选择

Tomcat服务器创建成功

  1. Create a new dynamic web project创建一个新的动态 Web 项目

创建一个新的动态 Web 项目

Export war to tomcat server将war导出到tomcat服务器

将war导出到tomcat服务器

  1. Tomcat debug configuration(important), first double click tomcat server, then select "Use Tomcat installation (takes control of Tomcat installation)" Tomcat调试配置(重要),首先双击tomcat服务器,然后选择“使用Tomcat安装(控制Tomcat安装)”

Tomcat 调试配置——重要!

  1. Add breakpoints添加断点

添加断点

  1. Run tomcat in debug mode在调试模式下运行 tomcat

在调试模式下运行 tomcat

  1. Test war in web browser在网络浏览器中测试战争

在网络浏览器中测试战争

  1. Edit source path编辑源路径

编辑源路径——步骤 1

编辑源路径——第 2 步

  1. Debug source code in Tomcat在Tomcat中调试源代码

在Tomcat中调试源代码

The war file is available here .战争文件可在此处获得

Simply change the line in startup.bat (if you are using Windows)只需更改startup.bat的行(如果您使用的是 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.是的,您需要配置 tomcat 以接受远程调试连接。 There is a FAQ on how to do it with various IDEs.有一个关于如何使用各种 IDE 执行此操作的常见问题解答。

http://wiki.apache.org/tomcat/FAQ/Developing#Q2 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.右键单击要调试的项目,然后转到 Debug As 菜单,然后在列表中单击 Debug Configurations。

步骤 1. 图像描述

  1. Then Double click on the Remote Java Application from left menu list.然后双击左侧菜单列表中的远程 Java 应用程序。 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.还将侦听端口更改为 7999,然后在从本地主机启动 Web 应用程序后,单击同一窗口上的调试按钮。 Then any break point's will be hit after that.然后将在此之后击中任何断点。

步骤 2. 图像描述

Steps to setup the tomcat Debugger with eclipse使用 Eclipse 设置 tomcat 调试器的步骤

Install the following things:安装以下东西:

java 1.8+爪哇 1.8+

eclipse EE version日食EE版

download tomcat 8+下载 tomcat 8+

open eclipse and go to servers tab and add a new server(window-> show View-> Others -> Search Servers)打开 Eclipse 并转到servers选项卡并添加一个新服务器(窗口-> 显示视图-> 其他 -> 搜索服务器)

Mark your project as Dynamic web Project(Rightclick on Project-> project facets -> select Dynamic web module)将您的项目标记为动态 Web 项目(右键单击项目-> 项目构面-> 选择动态 Web 模块)

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在调试或运行模式下启动 tomcat 服务器

check on localhost:8080检查localhost:8080

Debug worked for me.调试对我有用。 I was using tomcat 8, configured on centos 7. Debug port opened for me after changing 2 settings.我使用的是在 centos 7 上配置的 tomcat 8。更改 2 个设置后为我打开了调试端口。

  1. Open tomcat/conf/bin/startup.sh and added below lines打开 tomcat/conf/bin/startup.sh 并添加以下行
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
  1. In the same file startup.sh, added jpda before start command.在同一个文件startup.sh中,在start命令前添加了jpda
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"

Restart the tomcat.重启tomcat。 In eclipse go to Run>Debug configuration>Remote java application>Add host ip and port(8000) where tomcat is running.在 Eclipse 中,转到运行>调试配置>远程 java 应用程序>添加运行 tomcat 的主机 ip 和端口(8000) In my case i required to open 8000 through firewall too.就我而言,我也需要通过防火墙打开 8000。

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.除了远程调试之外,如果您在 eclipse 中添加了 tomcat,您还可以在 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.如果您有多模块 maven 项目,请在服务器上调试刚刚显示为带有 war 包装的模块。 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.如果你想调试一个自己在启动时运行的类,比如用@PostConstruct 注释的方法,记住你应该增加服务器超时。 To do that, go to server view and double click on tomcat and in server preview tab, increase the timeout value.为此,请转到服务器视图并双击 tomcat 并在服务器预览选项卡中增加超时值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在tomcat中部署的Java应用程序中的异常行为 - Unusual behavior in java application deployed in tomcat 如何在Tomcat中部署的Eclipse中调试Java应用程序? - How to debug java application in Eclipse deployed in tomcat? 在Intellij IDEA中调试部署到Tomcat的Java Web App - Debugging Java Web App deployed to Tomcat in Intellij IDEA 部署在Tomcat上的Java应用程序无法连接到jdbc-mysql - Java application deployed on Tomcat doesn't connect to jdbc-mysql 使用提供静态内容的辅助tomcat文件夹调试java Web应用程序 - Debugging java web application with secondary tomcat folder serving static content 无法访问部署到Tomcat的应用程序 - Can not access application deployed to Tomcat 在tomcat中部署了Spring Boot Application - Deployed Spring boot Application in tomcat 如何以固定的时间间隔调用Java方法,该方法作为Web应用程序部署到Apache Tomcat服务器? - How to call Java method on patricular interval of time which is deployed to Apache Tomcat server as a web application? 无法使用Godaddy域名访问tomcat部署的Java Web应用程序 - Unable to access tomcat deployed java web application using godaddy domain name 如何获取部署在Apache Tomcat 7上的Java Web应用程序的正常运行时间报告? - How to get the up time report for a Java Web Application deployed on Apache Tomcat 7?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM