简体   繁体   中英

Start tomcat7:run maven plugin within eclipse and debug

I want to debug a webapp in eclipse. 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.

Details
The webapp is a maven artifact and I use the m2e plugin in eclipse to bridge between maven and eclipse.

I've managed to start the tomcat server from within eclipse. The webapp is started in tomcat nicely, also in debug mode if I choose so:

  • in eclipse, right-click project
  • Run As > Maven build... (NOT "Maven build")
  • a window opens. In the text field "Goals", enter "tomcat7:run"
  • click Apply
  • click Run

The tomcat server starts up running and its stdlog is printed to a window within 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. 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)
If tomcat is forked in another VM, then you need to add the parameter forkMode with a value of never . This allows eclipse to "look through" to tomcat's VM and set breakpoints there.

Problem+Solution 2 (source)
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. 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.
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.

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

you can run tomcat with maven with this command:

mvn tomcat7:run

and if you want to debug, set this maven options:

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

if you are in windows, use the set command:

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

then you can debug with Eclipse's Remote Java Application .

Hope this help.

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