Tomcat Maven plugin and IntelliJ IDEA issues

Maven Jun 11, 2017

Tomcat Maven plugin helps to deploy WAR packages to Tomcat servlet container without manually downloading and installing it on your machine. It works without any issues for the maven "clean tomcat7:run" command from the terminal. But for some reason, IntelliJ IDEA doesn’t recognize the plugins automatically. Here are the two issues I have found and trying find a fix as well.

The tomcat7-maven-plugin won’t show up in the Maven Projects side panel.

Normally in the POM file, under <build> there is a <pluginManagement> block where you add the plugins with all the configuration. But IntelliJ won’t recognize the tomcat7-maven-plugin plugin and auto show in the Maven Plugins panel to let you run/deploy the build from IDE UI.

To fix it I had to add the plugin separately under build tag.

Here is the POM after the change,

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/</path>
                    <contextReloadable>true</contextReloadable>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

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

And the Maven Projects Side panel,
Screen Shot 2017-06-11 at 3.47.06 PM
Then you can select the options you want and then create a Run configuration to reuse.

The tomcat7-maven-plugin is not auto-reloading the context after any change in the code.

In the POM configuration I have <contextReloadable>true</contextReloadable>, so the plugin should auto recompile and reload all the new code changes.

Under the Preference > Compiler there is an option "Build project automatically". I have turned it on, but still, it won’t recompile automatically.

I have to always use Shift+Command+F9 shortcut to reload the context. I think I like this option better, instead of recompiling on every save. I tend to press Command+S very frequently.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.