简体   繁体   English

启动tomcat7:在eclipse和debug中运行maven插件

[英]Start tomcat7:run maven plugin within eclipse and debug

I want to debug a webapp in eclipse. 我想在eclipse中调试一个webapp。 I get to the point where tomcat and the webapp are ran inside of eclipse in debug mode, but then breakpoints in the webapp code have no effect. 我发现tomcat和webapp在调试模式下在eclipse中运行,但是webapp代码中的断点没有任何效果。

Details 细节
The webapp is a maven artifact and I use the m2e plugin in eclipse to bridge between maven and eclipse. webapp是一个maven工件,我在eclipse中使用m2e插件来连接maven和eclipse。

I've managed to start the tomcat server from within eclipse. 我已经设法从eclipse中启动tomcat服务器。 The webapp is started in tomcat nicely, also in debug mode if I choose so: webapp很好地在tomcat中启动,如果我这样选择,也可以在调试模式下启动:

  • in eclipse, right-click project 在eclipse中,右键单击项目
  • Run As > Maven build... (NOT "Maven build") 运行方式> Maven构建...(不是“Maven构建”)
  • a window opens. 一个窗口打开。 In the text field "Goals", enter "tomcat7:run" 在文本字段“目标”中,输入“tomcat7:run”
  • click Apply 单击“应用”
  • click Run 单击运行

The tomcat server starts up running and its stdlog is printed to a window within eclipse. tomcat服务器启动运行,其stdlog打印到eclipse中的窗口。 I can also stop it conveniently and start it again in debug mode. 我也可以方便地停止它并在调试模式下再次启动它。 So far, that's what I want and what I expect. 到目前为止,这就是我想要的和我期望的。

Problem 问题
I set a breakpoint in the code of my webapp and restart tomcat in debug mode from within eclipse. 我在webapp的代码中设置了一个断点,并在eclipse中以调试模式重启tomcat。 Now, the breakpoint isn't active: It doesn't have that little tickmark that active breakpoints have and I know the code is executed, but it doesn't stop at the breakpoint. 现在,断点未激活:它没有活动断点所具有的那个小刻度,我知道代码已执行,但它不会在断点处停止。

There can be two ways to fix this and you will need one or both of them. 有两种方法可以解决这个问题,你需要其中一种或两种。 Open your run configuration, then 然后打开运行配置

Problem+Solution 1 (fork) 问题+解决方案1(分叉)
If tomcat is forked in another VM, then you need to add the parameter forkMode with a value of never . 如果tomcat在另一个VM中分叉,那么您需要添加值为never的参数forkMode This allows eclipse to "look through" to tomcat's VM and set breakpoints there. 这允许eclipse“浏览”到tomcat的VM并在那里设置断点。

Problem+Solution 2 (source) 问题+解决方案2(来源)
In certain setups with maven parent and child artifacts, it can happen that eclipse is not aware that the source of some child project belong to your webapp. 在具有maven父项和子项工件的某些设置中,可能会发生eclipse不知道某个子项目的源属于您的webapp。 The symptom of this is that the execution is stopped at a breakpoint, but eclipse does not automatically jump to the source location and instead tells you that the source is unknown. 这种情况的症状是执行在断点处停止,但是eclipse不会自动跳转到源位置,而是告诉您源是未知的。
To solve this, you need to add the source of the child project to your run configuratuon: In your run configuration, go to Source > Add... > Java Project and pick all relevant projects which contain source code you might want to debug. 要解决此问题,您需要将子项目的源添加到运行配置中:在运行配置中,转到Source> Add ...> Java Project并选择包含您可能要调试的源代码的所有相关项目。

转到eclipse调试视图,如果选中该复选框,请检查断点的断点选项卡视图。

you can run tomcat with maven with this command: 您可以使用此命令运行带有maven的tomcat:

mvn tomcat7:run

and if you want to debug, set this maven options: 如果要调试,请设置此maven选项:

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

if you are in windows, use the set command: 如果您在Windows中,请使用set命令:

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

then you can debug with Eclipse's Remote Java Application . 然后你可以使用Eclipse的Remote Java Application进行调试。

Hope this help. 希望这有帮助。

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

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