Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My issue is that i can't run remote debug with tomcat7-maven-plugin. What i use:

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

Ofc Maven is provided by default with IntelliJ. I already tried with mvnDebug tomcat7:run command but intelliJ doesn't resolve mvnDebug phrase in maven's built-in command line. Can't use cmd command line neither because i can't find 'home' path since maven is built-in intelliJ. Tried configure remote-debug with intelli also but get confused. Also can't find tomcat7 plugin in "Maven Projects" window. But i'm sure it is, since tomcat7:run command starts tomcat container and app works.

like image 560
Piotr Bartoch Avatar asked Nov 20 '16 11:11

Piotr Bartoch


People also ask

How do I run Maven in debug mode IntelliJ?

In the IDE, add debug points where you want the debugger to pause during execution. Then in the terminal, enter your Maven execution command, replacing mvn with mvnDebug . In IntelliJ, make sure your debugging configuration is selected, then press the “Debug” button.

What is Tomcat7 Maven plugin?

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


1 Answers

In Intellij IDEA, in the Maven Projects tab, dig down to the tomcat7:run goal and then right click and select Debug like so:

enter image description here

In the abouve, notice that there is a breakpoint on Line 34 of HelloServlet.java. Now as soon as you hit the URL mapped to the servlet (http://localhost:9090/hello in this case), the breakpoint gets hit as seen below:

enter image description here

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

Regarding not being able to see Plugins in Maven Projects (sorry I missed that you've mentioned this), note that Plugins is not a top level node in 'Maven Projects' .. but will be under a node named taken from <name> of your project's root pom. Based on my own experience with Intellij 2016.x as well as on the fact that this functionality is pretty basic, I'd be quite surprised if this is a bug in Intellij. I'd suggest that this is either a problem with your pom.xml or a (shudder!) user error.


Update - Plugins not visible in Maven Projects

From the pom.xml (here), the tomcat7 plugin is in the build -> pluginManagement -> plugins section. This section is intended to be used in a root pom (as you have) to centralize the plugin configuration which can then be inherited by any of the child modules by simply mentioning the plugin. But without doing so, the tomcat7 plugin will not be available anywhere. Therefore, you must have a build -> plugins -> plugin section with the tomcat7 maven plugin somewhere (Also see relevant 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 <build> section of your root pom, immediately results in the Plugins section, along with the tomcat7 goals, to appear in Maven Projects :

enter image description here

like image 185
Ashutosh Jindal Avatar answered Sep 25 '22 13:09

Ashutosh Jindal