Start tomcat7: run maven plugin in eclipse and debug

I want to debug webapp in eclipse. I got to the point where tomcat and webapp start inside eclipse in debug mode, but then breakpoints in webapp code have no effect.

More details
Webapp is a maven artifact, and I use the m2e plugin in eclipse to transition between maven and eclipse.

I managed to start the tomcat server from inside eclipse. Webapp starts up in tomcat beautifully, also in debug mode, if I choose this:

  • in eclipse, right click on project
  • Run as> Maven build ... (NOT "Maven build")
  • a window will open. In the "Targets" text box, enter "tomcat7: run"
  • click "apply"
  • click "Run"

The tomcat server starts and its stdlog prints to a window inside eclipse. I can also stop it conveniently and run it again in debug mode. So far I want and what I expect.

Problem
I set a breakpoint in my webapp code and restarted tomcat in debug mode from inside eclipse. Now the breakpoint is not active: it does not have such a small mark that has active breakpoints, and I know that the code is executed, but it does not stop at the breakpoint.

+5
source share
3 answers

You can fix this in two ways, and you will need one or both of them. Open the run configuration, then

Problem + solution 1 (fork)
If tomcat is forked on another virtual machine, you need to add the forkMode parameter with a value of never . This allows eclipse to "view" the tomcat VM and set breakpoints there.

Problem + solution 2 (source)
In some installations with maven parent and child artifacts, it may happen that eclipse does not know that the source of any child project belongs to your webapp. The symptom of this is that execution stops at the breakpoint, but the eclipse does not automatically go back to its original location and instead tells you that the source is unknown.
To solve this problem, you need to add the source of the child project to the launch configuration. In the launch configuration, go to Source> Add ...> Java Project and select all the relevant projects that contain the source code that you might want to debug.

+2
source

Switch to eclipse debug mode, check the breakpoint tab tab for the breakpoint, if checked.

0
source

you can start tomcat using maven with this command:

mvn tomcat7:run

and if you want to debug, set the following 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 using Eclipse Remote Java Application .

I hope for this help.

0
source

Source: https://habr.com/ru/post/1215781/


All Articles