How to run tomcat7-maven-plugin in debug mode with IntelliJ IDEA

My problem is that I cannot start remote debugging using tomcat7-maven-plugin. What I use:

  • Maven
  • Tomcat7 plugin for maven
  • IntelliJ IDEA Ultimate 2016.2.2

Ofc Maven is provided by default with IntelliJ. I already tried with mvnDebug tomcat7: execute the command, but intelliJ does not allow the phrase mvnDebug in the maven built-in command line. It is impossible to use the cmd command line either because I cannot find the "home" path, since maven is built into intelliJ. I tried setting up remote debugging using Intelli, but got confused. Also unable to find the tomcat7 plugin in the "Maven Projects" window. But I'm sure it is, since tomcat7: the launch command launches the container and the tomcat application.

+9
source share
3 answers

In Intellij IDEA, on the Maven Projects tab, navigate to the tomcat7:run target, and then right-click and select Debug as follows:

enter image description here

In abouve, notice that line 34 has a breakpoint HelloServlet.java . Now, as soon as you hit the URL associated with the servlet ( http: // localhost: 9090 / hello in this case), the breakpoint will hit, as shown below:

enter image description here

The code used to verify this is in the following repository: https://github.com/javacreed/how-to-run-embedded-tomcat-with-maven

Regarding the inability to see Plugins in Maven Projects (sorry, I missed what you mentioned about this), note that Plugins not the top level node in 'Maven Projects' .. but will be under the node symbol taken from your <name> root pom project. Based on my own experience with Intellij 2016.x, as well as the fact that this functionality is pretty simple, I would be very surprised if this is a bug in Intellij. I would suggest that this is either a problem with your pom.xml error, or with (shudder!).


Update - Plugins not showing up in Maven Projects

From pom.xml ( here ), the tomcat7 plugin is located in the build -> pluginManagement -> plugins section. This section is intended to be used in the root folder (like yours) to centralize the configuration of the plugin, which can then be inherited by any of the child modules by simply specifying the plugin. But without this, the tomcat7 plugin would not be available anywhere. Therefore, you should have a build -> plugins -> plugin section with the tomcat7 maven plugin somewhere (also see the corresponding question: Maven: What is pluginManagement? )

For example, the following change ( here is the corresponding pull request for your repo):

  <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> </plugin> </plugins> 

Added to the <build> section of your pom root, it immediately causes the Plugins section along with the tomcat7 targets to appear in Maven Projects :

enter image description here

+20
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 Eclipse or Intellij.

I hope for this help.

+7
source

This is a late answer, but I would like to highlight another more friendly solution that uses the same idea as the answer to @arganzheng. You can add debugging options as part of the tomcat maven plugin configuration. The resulting pom will look like this

 <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <systemProperties> <MAVEN_OPTS>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</MAVEN_OPTS> </systemProperties> </configuration> </plugin> </plugins> 
0
source

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


All Articles