Search code examples
mavenintellij-ideaservletsmenujetty

Jetty sub-menu in "Plugins" area of Maven panel in IntelliJ


In the past, I have seen a Jetty sub-menu in the Maven panel of IntelliJ. In the trio of Lifecycle, Plugins, and Dependencies hierarchies, the Plugins list of elements would include a Jetty item. I could expand that item to see Jetty commands such as Run. Double-clicking that item would run the web app project using Jetty.

In creating my own simple example web app project in IntelliJ IDEA 2023.3.2 (Ultimate Edition), I have configured the Jetty Maven plugin. This works, as I can hit Control key twice to bring up the IntelliJ Run anything where I can execute mvn jetty:run to successfully run my web app.

However, there is no Jetty sublist of commands under the Maven panel > Plugins list.

screenshot of Maven panel in IntelliJ missing its list of Jetty commands

👉🏽 How to get a list of Jetty commands to be displayed within the Maven window pane of IntelliJ?

In my POM I have an element for the latest version of the Jetty Maven plugin:

<plugin>
    <groupId>org.eclipse.jetty.ee10</groupId>
    <artifactId>jetty-ee10-maven-plugin</artifactId>
    <version>12.0.5</version>
</plugin>

Here is the full POM:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>hello-world</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>Jetty HellowWorld Webapp</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>21</maven.compiler.release>
        <jettyVersion>12.0.5</jettyVersion>
    </properties>

    <dependencies>

        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.10.1</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
            <scope>provided</scope>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/jakarta.servlet.jsp/jakarta.servlet.jsp-api -->
        <dependency>
            <groupId>jakarta.servlet.jsp</groupId>
            <artifactId>jakarta.servlet.jsp-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <finalName>ExServletMySQL</finalName>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.3.2</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.3.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.11.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.1.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>3.1.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>3.1.1</version>
                </plugin>

                <plugin>
                    <groupId>org.eclipse.jetty.ee10</groupId>
                    <artifactId>jetty-ee10-maven-plugin</artifactId>
                    <version>12.0.5</version>
                </plugin>

            </plugins>
        </pluginManagement>
    </build>
</project>

Solution

  • Move <plugin> element to outside of <pluginManagement>

    Change your POM to move the <plugin> element for jetty-ee10-maven-plugin to be outside the grouping element <pluginManagement>.

    This does indeed work; The jetty group of commands does appear in the Plugins hierarchy of the Maven window pane in IntelliJ.

    screenshot of Maven window pane in IntelliJ, now with group labeled "Jetty"

    Caveat: I have no idea of the downsides or implications of this different location within the POM. And I do not understand the purpose of <pluginManagement>.

    So your new POM would look like this:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.example</groupId>
        <artifactId>hello-world</artifactId>
        <version>0.1-SNAPSHOT</version>
        <packaging>war</packaging>
    
        <name>Jetty HellowWorld Webapp</name>
        <!-- FIXME change it to the project's website -->
        <url>http://www.example.com</url>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.release>21</maven.compiler.release>
        </properties>
    
        <dependencies>
    
            <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.10.1</version>
                <scope>test</scope>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
            <dependency>
                <groupId>jakarta.servlet</groupId>
                <artifactId>jakarta.servlet-api</artifactId>
                <version>6.0.0</version>
                <scope>provided</scope>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/jakarta.servlet.jsp/jakarta.servlet.jsp-api -->
            <dependency>
                <groupId>jakarta.servlet.jsp</groupId>
                <artifactId>jakarta.servlet.jsp-api</artifactId>
                <version>3.0.0</version>
                <scope>provided</scope>
            </dependency>
    
        </dependencies>
    
        <build>
            <finalName>ExServletMySQL</finalName>
            <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
                <plugins>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.3.2</version>
                    </plugin>
                    <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.3.1</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.11.0</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.1.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>3.2.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-install-plugin</artifactId>
                        <version>3.1.1</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>3.1.1</version>
                    </plugin>
    
                </plugins>
            </pluginManagement>
    
            <plugins>
                <plugin>
                    <groupId>org.eclipse.jetty.ee10</groupId>
                    <artifactId>jetty-ee10-maven-plugin</artifactId>
                    <version>12.0.5</version>
                    <configuration>
                        <httpConnector>
                            <port>8080</port>
                        </httpConnector>
                    </configuration>
                </plugin>
            </plugins>
    
        </build>
    </project>
    

    Credit for this workaround goes to the folks at JavaPointers.com for their page, How to add Maven Jetty Plugin. To quote:

    Other developers encountered an issue wherein IntelliJ is not showing the Jetty plugin in the Maven tab. It might be because you have added the Jetty plugin under the PluginManagement section. To resolve this, move the jetty plugin outside and just add it as a child in build > plugins section.