6

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.

Daniel S.
  • 6,458
  • 4
  • 35
  • 78
  • I know I can set up remote debugging in maven and then run the tomcat7 in maven and connect to it with eclipse remote debugging. But then I have to manage starting and stopping two things seprately and I won't see the log output of tomcat in eclipse ready-to-click-on exceptions. I need both of these advantages. If that all works another way, I'm also fine. – Daniel S. Mar 20 '15 at 18:46
  • Why aren't you using a Tomcat server instance inside Eclipse, instead of relying on the Maven plugin? – watery Mar 20 '15 at 20:21
  • 1
    @watery I could and I will if my other way doesn't work out. The main reason is that the maven plugin has one configuration and if something changes there, I will automatically have that change reflected when starting tomcat through the maven plugin. If I have a tomcat server configured in eclipse, then the config change from maven won't have an effect in my eclipse. Thus, if I do that, I might run tomcat in another way compared to how my teammates run it, thus we might experience different sets of problems at some point, leading to difficulties in following eachothers problem descriptions. – Daniel S. Mar 21 '15 at 10:44
  • Maybe this helps: http://stackoverflow.com/questions/12598261/maven-build-debug-in-eclipse – Calon Mar 23 '15 at 10:28
  • @Calon this looks promising. I will try it later today. – Daniel S. Mar 23 '15 at 10:30

3 Answers3

3

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.

dreua
  • 527
  • 2
  • 15
0

Go to eclipse debug view, check the break point tab view for your break point if the checkbox is checked.

0

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.

arganzheng
  • 1,294
  • 15
  • 20
  • All you wrote was apperently known before; see comments to question. Moreover, it's stated in comments that this solution is not ideal and it's explained why. So you simply duplicated information which is on this page, and which is not helpful. Moreover, there already is a better solution than yours. sorry for the devastating comment, but I think it's worth to point out. – Daniel S. Nov 30 '17 at 13:52