Running your Application with Maven
The plugin includes a run goal which can be used to launch your application from the command line, as shown in the following example:
$ mvn spring-boot:run
Application arguments can be specified using the arguments
parameter, see using application arguments for more details.
The application is executed in a forked process and setting properties on the command-line will not affect the application.
If you need to specify some JVM arguments (that is for debugging purposes), you can use the jvmArguments
parameter, see Debug the application for more details.
There is also explicit support for system properties and environment variables.
As enabling a profile is quite common, there is dedicated profiles
property that offers a shortcut for -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev"
, see Specify active profiles.
Spring Boot devtools
is a module to improve the development-time experience when working on Spring Boot applications.
To enable it, just add the following dependency to your project:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
When devtools
is running, it detects changes when you recompile your application and automatically refreshes it.
This works for not only resources but code as well.
It also provides a LiveReload server so that it can automatically trigger a browser refresh whenever things change.
Devtools can also be configured to only refresh the browser whenever a static resource has changed (and ignore any change in the code). Just include the following property in your project:
spring.devtools.remote.restart.enabled=false
Prior to devtools
, the plugin supported hot refreshing of resources by default which has now been disabled in favour of the solution described above.
You can restore it at any time by configuring your project:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
When addResources
is enabled, any src/main/resources
directory will be added to the application classpath when you run the application and any duplicate found in the classes output will be removed.
This allows hot refreshing of resources which can be very useful when developing web applications.
For example, you can work on HTML, CSS or JavaScript files and see your changes immediately without recompiling your application.
It is also a helpful way of allowing your front end developers to work without needing to download and install a Java IDE.
A side effect of using this feature is that filtering of resources at build time will not work. |
In order to be consistent with the repackage
goal, the run
goal builds the classpath in such a way that any dependency that is excluded in the plugin’s configuration gets excluded from the classpath as well.
For more details, see the dedicated example.
Sometimes it is useful to run a test variant of your application.
For example, if you want to use Testcontainers at development time or make use of some test stubs.
Use the test-run
goal with many of the same features and configuration options as run
for this purpose.
spring-boot:run
org.springframework.boot:spring-boot-maven-plugin:3.3.5
Run an application in place.
Optional parameters
Name | Type | Default |
---|---|---|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
|
|
|
||
|
|
|
|
||
|
|
|
|
Parameter details
addResources
Add maven resources to the classpath directly, this allows live in-place editing of resources. Duplicate resources are removed from target/classes
to prevent them from appearing twice if ClassLoader.getResources()
is called. Please consider adding spring-boot-devtools
to your project instead as it provides this feature and many more.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
additionalClasspathElements
Additional classpath elements that should be added to the classpath. An element can be a directory with classes and resources or a jar file.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
agents
Path to agent jars.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
arguments
Arguments that should be passed to the application.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
classesDirectory
Directory containing the classes and resource files that should be used to run the application.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
commandlineArguments
Arguments from the command line that should be passed to the application. Use spaces to separate multiple arguments and make sure to wrap multiple values between quotes. When specified, takes precedence over #arguments
.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
directories
Additional directories containing classes or resources that should be added to the classpath.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
environmentVariables
List of Environment variables that should be associated with the forked process used to run the application.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
excludeGroupIds
Comma separated list of groupId names to exclude (exact match).
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
excludes
Collection of artifact definitions to exclude. The Exclude
element defines mandatory groupId
and artifactId
components and an optional classifier
component. When configured as a property, values should be comma-separated with colon-separated components: groupId:artifactId,groupId:artifactId:classifier
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
includes
Collection of artifact definitions to include. The Include
element defines mandatory groupId
and artifactId
components and an optional classifier
component. When configured as a property, values should be comma-separated with colon-separated components: groupId:artifactId,groupId:artifactId:classifier
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
jvmArguments
JVM arguments that should be associated with the forked process used to run the application. On command line, make sure to wrap multiple values between quotes.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
mainClass
The name of the main class. If not specified the first compiled class found that contains a 'main' method will be used.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
noverify
Flag to say that the agent requires -noverify.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
optimizedLaunch
Whether the JVM’s launch should be optimized.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
profiles
The spring profiles to activate. Convenience shortcut of specifying the 'spring.profiles.active' argument. On command line use commas to separate multiple profiles.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
skip
Skip the execution.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
systemPropertyVariables
List of JVM system properties to pass to the process.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
spring-boot:test-run
org.springframework.boot:spring-boot-maven-plugin:3.3.5
Run an application in place using the test runtime classpath. The main class that will be used to launch the application is determined as follows: The configured main class, if any. Then the main class found in the test classes directory, if any. Then the main class found in the classes directory, if any.
Required parameters
Name | Type | Default |
---|---|---|
|
|
|
|
|
Optional parameters
Name | Type | Default |
---|---|---|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
|
|
|
||
|
|
|
|
||
|
Parameter details
addResources
Add maven resources to the classpath directly, this allows live in-place editing of resources. Duplicate resources are removed from target/classes
to prevent them from appearing twice if ClassLoader.getResources()
is called. Please consider adding spring-boot-devtools
to your project instead as it provides this feature and many more.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
additionalClasspathElements
Additional classpath elements that should be added to the classpath. An element can be a directory with classes and resources or a jar file.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
agents
Path to agent jars.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
arguments
Arguments that should be passed to the application.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
classesDirectory
Directory containing the classes and resource files that should be used to run the application.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
commandlineArguments
Arguments from the command line that should be passed to the application. Use spaces to separate multiple arguments and make sure to wrap multiple values between quotes. When specified, takes precedence over #arguments
.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
directories
Additional directories containing classes or resources that should be added to the classpath.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
environmentVariables
List of Environment variables that should be associated with the forked process used to run the application.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
excludeGroupIds
Comma separated list of groupId names to exclude (exact match).
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
excludes
Collection of artifact definitions to exclude. The Exclude
element defines mandatory groupId
and artifactId
components and an optional classifier
component. When configured as a property, values should be comma-separated with colon-separated components: groupId:artifactId,groupId:artifactId:classifier
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
includes
Collection of artifact definitions to include. The Include
element defines mandatory groupId
and artifactId
components and an optional classifier
component. When configured as a property, values should be comma-separated with colon-separated components: groupId:artifactId,groupId:artifactId:classifier
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
jvmArguments
JVM arguments that should be associated with the forked process used to run the application. On command line, make sure to wrap multiple values between quotes.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
mainClass
The name of the main class. If not specified the first compiled class found that contains a 'main' method will be used.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
noverify
Flag to say that the agent requires -noverify.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
optimizedLaunch
Whether the JVM’s launch should be optimized.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
profiles
The spring profiles to activate. Convenience shortcut of specifying the 'spring.profiles.active' argument. On command line use commas to separate multiple profiles.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
skip
Skip the execution.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
systemPropertyVariables
List of JVM system properties to pass to the process.
Name |
|
---|---|
Type |
|
Default value |
|
User property |
|
Since |
|
Examples
Debug the Application
The run
and test-run
goals run your application in a forked process.
If you need to debug it, you should add the necessary JVM arguments to enable remote debugging.
The following configuration suspend the process until a debugger has joined on port 5005:
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005
</jvmArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
These arguments can be specified on the command line as well:
$ mvn spring-boot:run -Dspring-boot.run.jvmArguments=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005
Using System Properties
System properties can be specified using the systemPropertyVariables
attribute.
The following example sets property1
to test
and property2
to 42:
<project>
<build>
<properties>
<my.value>42</my.value>
</properties>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<property1>test</property1>
<property2>${my.value}</property2>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
If the value is empty or not defined (that is <my-property/
>), the system property is set with an empty String as the value.
Maven trims values specified in the pom, so it is not possible to specify a System property which needs to start or end with a space through this mechanism: consider using jvmArguments
instead.
Any String typed Maven variable can be passed as system properties.
Any attempt to pass any other Maven variable type (for example a List
or a URL
variable) will cause the variable expression to be passed literally (unevaluated).
The jvmArguments
parameter takes precedence over system properties defined with the mechanism above.
In the following example, the value for property1
is overridden
:
$ mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dproperty1=overridden"
Using Environment Variables
Environment variables can be specified using the environmentVariables
attribute.
The following example sets the 'ENV1', 'ENV2', 'ENV3', 'ENV4' env variables:
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<environmentVariables>
<ENV1>5000</ENV1>
<ENV2>Some Text</ENV2>
<ENV3/>
<ENV4></ENV4>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
If the value is empty or not defined (that is <MY_ENV/
>), the env variable is set with an empty String as the value.
Maven trims values specified in the pom so it is not possible to specify an env variable which needs to start or end with a space.
Any String typed Maven variable can be passed as system properties.
Any attempt to pass any other Maven variable type (for example a List
or a URL
variable) will cause the variable expression to be passed literally (unevaluated).
Environment variables defined this way take precedence over existing values.
Using Application Arguments
Application arguments can be specified using the arguments
attribute.
The following example sets two arguments: property1
and property2=42
:
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<arguments>
<argument>property1</argument>
<argument>property2=${my.value}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
On the command-line, arguments are separated by a space the same way jvmArguments
are.
If an argument contains a space, make sure to quote it.
In the following example, two arguments are available: property1
and property2=Hello World
:
$ mvn spring-boot:run -Dspring-boot.run.arguments="property1 'property2=Hello World'"
Specify Active Profiles
The active profiles to use for a particular application can be specified using the profiles
argument.
The following configuration enables the local
and dev
profiles:
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>local</profile>
<profile>dev</profile>
</profiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
The profiles to enable can be specified on the command line as well, make sure to separate them with a comma, as shown in the following example:
$ mvn spring-boot:run -Dspring-boot.run.profiles=local,dev