Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 663
Daniel S. Avatar asked Mar 20 '15 18:03

Daniel S.


People also ask

What is tomcat7 Maven plugin?

The Tomcat7 Maven Plugin provides goals to manipulate WAR projects within the Tomcat servlet container version 7.x.

How do I run maven deploy in eclipse?

Assuming that you installed the m2eclipse Maven Eclipse plugin, right click your project or your pom, Run As>Maven build and enter the goal "deploy" on the goals line.


1 Answers

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.

like image 107
dreua Avatar answered Oct 05 '22 23:10

dreua