如何在 Eclipse 中单步调试/调试 Maven Web 项目
我有一个 Maven 项目,它是一个 Web 项目,并打包为一个 war。
当我想要部署时,我使用 tomcat-maven-plugin v1.2-SNAPSHOT 来执行 tomcat:deploy 。
但我的问题是我如何调试它/设置断点,就像我在 Eclipse 中对普通 web 项目所做的那样(其中显示调试感知并且服务器暂停。)
(我是这个领域的菜鸟)
[编辑]我不是问如何部署到TOMCAT。我只是问如何设置调试模式。仅供参考,我无法右键单击我的项目并选择运行>在服务器上运行,即使我已经通过 Maven 生成了 WTP 特定文件。
I have a Maven project which is a web project and is packaged as a war.
I use tomcat-maven-plugin v1.2-SNAPSHOT to do a tomcat:deploy when i want to deploy.
But my question is how do i debug it / set breakpoints like i can do for normal web projects in eclipse (where a Debugging perceptive is shown and the server is paused.)
(i am a noob in this field)
[EDIT] I am not asking how to deploy to TOMCAT. i am rather asking how to setup the debug mode .FYI i am not able to right click on my project and select run> run on server, even though i have generated WTP specific files through maven.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
mvn tomcat:deploy
将应用程序部署到外部 Tomcat 服务器。如果您想对其进行调试,则需要在启用调试的情况下运行该 Tomcat 服务器,并在 Eclipse 中设置远程调试配置文件。编辑:Tomcat wiki 上有一个简洁的指南来执行此操作。最简单的方法是使用
catalina jpda start
启动 Tomcat。这将在调试模式下启动 Tomcat,在端口 8000 上侦听调试器连接。然后在 Eclipse 中,创建一个“远程”启动器配置并告诉它连接到 localhost:8000。mvn tomcat:deploy
deploys an app to an external Tomcat server. If you want to debug that, you'll need to run that Tomcat server with debugging enabled and set up a remote debugging profile in Eclipse.Edit: There's a succinct guide to doing this on the Tomcat wiki. The simplest approach is to start Tomcat with
catalina jpda start
. That will start Tomcat in debug mode listening on port 8000 for debugger connections. Then in Eclipse, you create a "remote" launcher configuration and tell it to connect to localhost:8000.无论您是使用 maven 还是使用 Eclipse WTP 部署它,只要您启动了从 eclipse 部署到的服务器并且 eclipse 知道您部署的代码源放置在哪里,都没有关系。
请注意,如果您设置了
CATALINA_HOME
环境变量,这将用于通过mvn tomcat:deploy
进行部署。但您也可以在 pom.xml 的配置中定义它。It doesn't matter whether you deploy it with maven or with Eclipse WTP as long as you started the server to which you deploy from eclipse and eclipse knows where the sources of the code you deployed are placed.
Keep attention if you have set the
CATALINA_HOME
environment variable, this will used to deploy to withmvn tomcat:deploy
. But you can also define this in the configuration of thepom.xml
.我不确定通过 Maven 插件是否可行。
但您可以生成 Eclipse 特定文件:
mvn eclipse:eclipse -Dwtp.version=2.0
(WTP 版本取决于 Eclipse 的 WTP 版本)。然后,您可以更新项目并将其部署到 Tomcat 中,就像处理普通 Web 项目一样。
I'm not sure that it is feasible through the Maven plugin.
But you can generate eclipse specific files:
mvn eclipse:eclipse -Dwtp.version=2.0
(The WTP version depends on the WTP version of your Eclipse).Then, you can update your project and deploying it into a Tomcat like you can do for normal web projects.
此解决方案适用于我的情况,您可以尝试此
转到服务器视图。
双击 Tomcat 服务器。
您将获得服务器编辑器视图。
单击视图中的“模块”选项卡(底部)
单击添加外部 Web 模块,输入构建文件的路径(例如,C:\svn\projectName\trunk\test\project\target\webapp)并给出路径。
节省。
在服务器视图中右键单击 Tomcat。
选择调试。
如果您正在调试应用程序的启动,您可能需要在服务器视图中增加启动超时。
谢谢。
This solution worked in my case, you can try this
Go to the Servers view.
Double click on the Tomcat server.
You will get the server editor view.
Click on Modules tab in view (at bottom)
Click add External Web Module enter the path to your built files (e.g., C:\svn\projectName\trunk\test\project\target\webapp) and give a path.
Save.
Right-click on Tomcat in Servers view.
Choose Debug.
If you are debugging the startup of your application you might need to increase the startup timeout in the server view.
Thanks.