[英]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.需要注意的重要设置是
Host
和Port
字段。 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
选项卡上添加条目以确保所有源代码都可用于单步执行。
Export war to tomcat server将war导出到tomcat服务器
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
Then Double click on the Remote Java Application from left menu list.然后双击左侧菜单列表中的远程 Java 应用程序。 browse for the project u wanna add in then click apply.
浏览您要添加的项目,然后单击应用。
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 个设置后为我打开了调试端口。
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
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.