Close

Spring Boot Maven Plugin

[Last Updated: Oct 30, 2026]

Spring Boot provides a Maven plugin called spring-boot-maven-plugin.
Its goal prefix is spring-boot, so we call its goals like this:
spring-boot:<goal-name>.

These two goals are used most often:

  • spring-boot:run to run our Spring Boot application directly from the compiled classes (no jar file is needed).
  • spring-boot:repackage to turn a normal jar or war file into an executable jar or war file.

The plugin has a few more goals. For example,
build-image creates a container image,
build-info creates a build-info.properties file,
start and stop are used in integration tests,
process-aot is used for ahead-of-time processing (for example, for GraalVM native images).


Using Gradle instead of Maven? See the Spring Boot Gradle Plugin Tutorial.


Let's explore the plugin with an example.

Example


Adding the plugin in pom.xml

pom.xml

<project .....>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.1.2</version>
<relativePath></relativePath>
</parent>
<groupId>com.logicbig.example</groupId>
<artifactId>boot-mvn-plugin-example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>25</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.logicbig.example.MainClass</mainClass>
</configuration>
</plugin>

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

We do not need a <version> for the plugin. The spring-boot-starter-parent already manages it, so the plugin always has the same version as Spring Boot.



Listing the goals

Let's run mvn spring-boot:help at the location where we created our pom.xml. Maven finds the plugin version in our project (the parent pom manages it), so we see the goals of exactly the plugin version we use:


Output (filtered)
$ mvn spring-boot:help
Spring Boot Maven Plugin

This plugin has 3 goals:

spring-boot:help
Display help information on spring-boot-maven-plugin.
Call mvn spring-boot:help -Ddetail=true -Dgoal=<goal-name> to display
parameter details.

spring-boot:repackage
Repackages existing JAR and WAR archives so that they can be executed from the
command line using java -jar. With layout=NONE can also be used simply to
package a JAR with nested dependencies (and no main class, so not executable).

spring-boot:run
Run an executable archive application.

To see the parameters of the goals, we add -Ddetail=true. We can show a single goal with -Dgoal=run.

We can also use mvn help:describe. But this command does not read the plugin version from our pom. If we write -Dplugin=spring-boot or -Dplugin=org.springframework.boot:spring-boot-maven-plugin, Maven may show the newest version it can find (even a milestone version), and not the version our project uses. To describe an exact version we add it to the coordinates, for example -Dplugin=org.springframework.boot:spring-boot-maven-plugin:4.1.1.

Version note: the Spring Boot 1.2.0 plugin had only 3 goals: help, repackage and run. The goals build-info, start and stop were added later, so the 1.4.2 plugin had 6 goals. All of these goals still exist today. The five newer goals are build-image and build-image-no-fork (added in 2.3), process-aot and process-test-aot (added in 3.0), and test-run (added in 3.1).

Note: In Spring Boot 2.3.0, mvn spring-boot:help fails with "Type org.springframework.boot.maven.HelpMojo not present". After the Spring Boot build moved to Gradle, the plugin jar was published without the help class and its help data (issue #21556).



Main class

package com.logicbig.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class MainClass {
    public static void main (String[] args) {
        SpringApplication.run(MainClass.class, args);
    }

    @RestController
    private static class TheController {

        @RequestMapping("/")
        public String handle () {
            return "message from rest handler";
        }

    }
}

mvn spring-boot:run compiles our code and runs the application from the target/classes directory. It does not create a jar file.

D:\boot-mvn-plugin-example>mvn spring-boot:run
[INFO] Scanning for projects...

  ...............
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v4.1.1)

2026-10-13T10:15:02.411+08:00  INFO 12376 --- [           main] com.logicbig.example.MainClass           : Starting MainClass using Java 21.0.5 with PID 12376 (D:\boot-mvn-plugin-example\target\classes started by Joe in D:\boot-mvn-plugin-example)
2026-10-13T10:15:02.414+08:00  INFO 12376 --- [           main] com.logicbig.example.MainClass           : No active profile set, falling back to 1 default profile: "default"
  ...............
2026-10-13T10:15:03.561+08:00  INFO 12376 --- [           main] com.logicbig.example.MainClass           : Started MainClass in 1.186 seconds (process running for 1.532)

By default, the embedded Tomcat server listens on port 8080. Now we can access our application in the browser at http://localhost:8080:


Output
$ curl -s "http://localhost:8080"
message from rest handler

We can pass options to the application like this:

mvn spring-boot:run -Dspring-boot.run.profiles=dev
mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=9090


Packaging our application as an executable jar

Maven <packaging> is 'jar' by default. When we use spring-boot-starter-parent, the parent pom already binds the repackage goal to the Maven package phase. So, once the plugin is declared in our pom.xml, a simple mvn package creates the executable jar.


Output
D:\boot-mvn-plugin-example>mvn clean -q package

D:\boot-mvn-plugin-example>dir /s *.jar*
Volume in drive D:\boot-mvn-plugin-example\target

10/14/2026 07:30 AM 12,373,103 boot-mvn-plugin-example-1.0-SNAPSHOT.jar
10/14/2026 07:30 AM 4,649 boot-mvn-plugin-example-1.0-SNAPSHOT.jar.original
2 File(s) 12,377,752 bytes

Total Files Listed:
2 File(s) 12,377,752 bytes
0 Dir(s) 24,099,221,504 bytes free

The repackage goal replaces the normal jar with an executable jar that contains our classes and all the dependency jars. The normal jar is kept with the extra extension .original.

Now we can run the jar as follows, and access the application in the browser as before:

D:\boot-mvn-plugin-example>java -jar target\boot-mvn-plugin-example-1.0-SNAPSHOT.jar
 ........

We can also call the goal ourselves with mvn package spring-boot:repackage, but this is not needed when the goal is already bound to the package phase. It is useful only when we want to run the goal from the command line explicitly.



Adding the repackage goal manually

If we do not use spring-boot-starter-parent (for example, we have our own parent pom), then the repackage goal is not bound automatically. In that case we add the execution ourselves, and we also have to give the plugin version:

<project ....>

......
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>4.1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

After that, we just run this command to get an executable jar:

mvn package

Conflict between multiple main classes

Spring Boot automatically finds the 'main' class and runs it. If there is more than one main class, then we get the following error:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:4.1.1:run (default-cli) on project boot-mvn-plugin-example: Unable to find a single main class from the following candidates [com.logicbig.example.MainClass2, com.logicbig.example.MainClass] -> [Help 1]

To avoid that error we have to set the mainClass configuration:

<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
       <mainClass>com.logicbig.example.MainClass</mainClass>
     </configuration>
</plugin>

Or we can use a placeholder for the mainClass. It is a good idea to give the placeholder a default value in the pom properties. Otherwise the build fails when we do not pass the value:

<properties>
     <myMainClass>com.logicbig.example.MainClass</myMainClass>
</properties>
......
<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
       <mainClass>${myMainClass}</mainClass>
     </configuration>
</plugin>

and then run as:

mvn spring-boot:run -DmyMainClass=com.logicbig.example.MainClass2

For the run goal there is an even simpler way. It has a built-in property, so we do not need any pom change:

mvn spring-boot:run -Dspring-boot.run.main-class=com.logicbig.example.MainClass2

Example Project

Dependencies and Technologies Used:

  • Spring Boot 4.1.2
    Corresponding Spring Framework Version 7.0.10
     Version Compatibility: 1.2.0.RELEASE - 4.1.2Version List
    ×

    Version compatibilities of spring-boot-starter-parent with this example:

    • 1.2.0.RELEASE
    • 1.2.1.RELEASE
    • 1.2.2.RELEASE
    • 1.2.3.RELEASE
    • 1.2.4.RELEASE
    • 1.2.5.RELEASE
    • 1.2.6.RELEASE
    • 1.2.7.RELEASE
    • 1.2.8.RELEASE
    • 1.3.0.RELEASE
    • 1.3.1.RELEASE
    • 1.3.2.RELEASE
    • 1.3.3.RELEASE
    • 1.3.4.RELEASE
    • 1.3.5.RELEASE
    • 1.3.6.RELEASE
    • 1.3.7.RELEASE
    • 1.3.8.RELEASE
    • 1.4.0.RELEASE
    • 1.4.1.RELEASE
    • 1.4.2.RELEASE
    • 1.4.3.RELEASE
    • 1.4.4.RELEASE
    • 1.4.5.RELEASE
    • 1.4.6.RELEASE
    • 1.4.7.RELEASE
    • 1.5.0.RELEASE
    • 1.5.1.RELEASE
    • 1.5.2.RELEASE
    • 1.5.3.RELEASE
    • 1.5.4.RELEASE
    • 1.5.5.RELEASE
    • 1.5.6.RELEASE
    • 1.5.7.RELEASE
    • 1.5.8.RELEASE
    • 1.5.9.RELEASE
    • 1.5.10.RELEASE
    • 1.5.11.RELEASE
    • 1.5.12.RELEASE
    • 1.5.13.RELEASE
    • 1.5.14.RELEASE
    • 1.5.15.RELEASE
    • 1.5.16.RELEASE
    • 1.5.17.RELEASE
    • 1.5.18.RELEASE
    • 1.5.19.RELEASE
    • 1.5.20.RELEASE
    • 1.5.21.RELEASE
    • 1.5.22.RELEASE
    • 2.0.0.RELEASE
    • 2.0.1.RELEASE
    • 2.0.2.RELEASE
    • 2.0.3.RELEASE
    • 2.0.4.RELEASE
    • 2.0.5.RELEASE
    • 2.0.6.RELEASE
    • 2.0.7.RELEASE
    • 2.0.8.RELEASE
    • 2.0.9.RELEASE
    • 2.1.0.RELEASE
    • 2.1.1.RELEASE
    • 2.1.2.RELEASE
    • 2.1.3.RELEASE
    • 2.1.4.RELEASE
    • 2.1.5.RELEASE
    • 2.1.6.RELEASE
    • 2.1.7.RELEASE
    • 2.1.8.RELEASE
    • 2.1.9.RELEASE
    • 2.1.10.RELEASE
    • 2.1.11.RELEASE
    • 2.1.12.RELEASE
    • 2.1.13.RELEASE
    • 2.1.14.RELEASE
    • 2.1.15.RELEASE
    • 2.1.16.RELEASE
    • 2.1.17.RELEASE
    • 2.1.18.RELEASE
    • 2.2.0.RELEASE
    • 2.2.1.RELEASE
    • 2.2.2.RELEASE
    • 2.2.3.RELEASE
    • 2.2.4.RELEASE
    • 2.2.5.RELEASE
    • 2.2.6.RELEASE
    • 2.2.7.RELEASE
    • 2.2.8.RELEASE
    • 2.2.9.RELEASE
    • 2.2.10.RELEASE
    • 2.2.11.RELEASE
    • 2.2.12.RELEASE
    • 2.2.13.RELEASE
    • 2.3.0.RELEASE   Issue 21556
    • 2.3.1.RELEASE
    • 2.3.2.RELEASE
    • 2.3.3.RELEASE
    • 2.3.4.RELEASE
    • 2.3.5.RELEASE
    • 2.3.6.RELEASE
    • 2.3.7.RELEASE
    • 2.3.8.RELEASE
    • 2.3.9.RELEASE
    • 2.3.10.RELEASE
    • 2.3.11.RELEASE
    • 2.3.12.RELEASE
    • 2.4.0
    • 2.4.1
    • 2.4.2
    • 2.4.3
    • 2.4.4
    • 2.4.5
    • 2.4.6
    • 2.4.7
    • 2.4.8
    • 2.4.9
    • 2.4.10
    • 2.4.11
    • 2.4.12
    • 2.4.13
    • 2.5.0
    • 2.5.1
    • 2.5.2
    • 2.5.3
    • 2.5.4
    • 2.5.5
    • 2.5.6
    • 2.5.7
    • 2.5.8
    • 2.5.9
    • 2.5.10
    • 2.5.11
    • 2.5.12
    • 2.5.13
    • 2.5.14
    • 2.5.15
    • 2.6.0
    • 2.6.1
    • 2.6.2
    • 2.6.3
    • 2.6.4
    • 2.6.5
    • 2.6.6
    • 2.6.7
    • 2.6.8
    • 2.6.9
    • 2.6.10
    • 2.6.11
    • 2.6.12
    • 2.6.13
    • 2.6.14
    • 2.6.15
    • 2.7.0
    • 2.7.1
    • 2.7.2
    • 2.7.3
    • 2.7.4
    • 2.7.5
    • 2.7.6
    • 2.7.7
    • 2.7.8
    • 2.7.9
    • 2.7.10
    • 2.7.11
    • 2.7.12
    • 2.7.13
    • 2.7.14
    • 2.7.15
    • 2.7.16
    • 2.7.17
    • 2.7.18
    • Java 17 min
    • 3.0.0
    • 3.0.1
    • 3.0.2
    • 3.0.3
    • 3.0.4
    • 3.0.5
    • 3.0.6
    • 3.0.7
    • 3.0.8
    • 3.0.9
    • 3.0.10
    • 3.0.11
    • 3.0.12
    • 3.0.13
    • 3.1.0
    • 3.1.1
    • 3.1.2
    • 3.1.3
    • 3.1.4
    • 3.1.5
    • 3.1.6
    • 3.1.7
    • 3.1.8
    • 3.1.9
    • 3.1.10
    • 3.1.11
    • 3.1.12
    • 3.2.0
    • 3.2.1
    • 3.2.2
    • 3.2.3
    • 3.2.4
    • 3.2.5
    • 3.2.6
    • 3.2.7
    • 3.2.8
    • 3.2.9
    • 3.2.10
    • 3.2.11
    • 3.2.12
    • 3.3.0
    • 3.3.1
    • 3.3.2
    • 3.3.3
    • 3.3.4
    • 3.3.5
    • 3.3.6
    • 3.3.7
    • 3.3.8
    • 3.3.9
    • 3.3.10
    • 3.3.11
    • 3.3.12
    • 3.3.13
    • 3.4.0
    • 3.4.1
    • 3.4.2
    • 3.4.3
    • 3.4.4
    • 3.4.5
    • 3.4.6
    • 3.4.7
    • 3.4.8
    • 3.4.9
    • 3.4.10
    • 3.4.11
    • 3.4.12
    • 3.4.13
    • 3.5.0
    • 3.5.1
    • 3.5.2
    • 3.5.3
    • 3.5.4
    • 3.5.5
    • 3.5.6
    • 3.5.7
    • 3.5.8
    • 3.5.9
    • 3.5.10
    • 3.5.11
    • 3.5.12
    • 3.5.13
    • 3.5.14
    • 3.5.15
    • 3.5.16
    • 4.0.0
    • 4.0.1
    • 4.0.2
    • 4.0.3
    • 4.0.4
    • 4.0.5
    • 4.0.6
    • 4.0.7
    • 4.0.8
    • 4.0.9
    • 4.1.0
    • 4.1.1
    • 4.1.2

    Versions in green have been tested.

  • spring-boot-starter-web (Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container (deprecated in favor of spring-boot-starter-webmvc))
  • JDK 25

Spring Boot - Spring Maven Plugin Select All Download
  • boot-mvn-plugin-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
                • MainClass.java

    See Also

    Join