79

Usually I'm running my Spring Boot application with command:

mvn spring-boot:run -Drun.arguments=--server.port=9090 \
   -Dpath.to.config.dir=/var/data/my/config/dir

I want to set custom port to debug, so I can connect from eclipse. When I add arguments from example Spring Boot Maven Plugin

mvn spring-boot:run -Drun.arguments=--server.port=9090 \
   -Dpath.to.config.dir=/var/data/my/config/dir \
   -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787"

it works but other arguments like server.port or path.to.config.dir are no longer recognized and I get exception like:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class [com.my.app.Controller]; nested exception
is java.lang.IllegalArgumentException: Could not resolve placeholder
'path.to.config.dir' in string value
file:///${path.to.config.dir}/some.properties"

Question: How I can run with all arguments?

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
wbk
  • 1,310
  • 2
  • 11
  • 19
  • Exact solution in my case was to call: `mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787 -Dserver.port=9090 -Dpath.to.config.dir=/var/data/my/config/dir" ` – wbk Mar 25 '16 at 10:35
  • 1
    Link not working... – powder366 Nov 08 '17 at 10:22

6 Answers6

86

The parameter name has to be prefixed with spring-boot. as in -Dspring-boot.run.jvmArgument

The Spring Boot Reference Documentation, in the Debug the Application section, provided me the solution as I'm running Spring Boot 2.0.3

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
Stephane
  • 11,836
  • 25
  • 112
  • 175
  • 7
    This should be the accepted answer, the other answers didn't work – abarazal Mar 20 '20 at 01:13
  • 5
    This answer works for most, however it is not working for me in PowerShell, the message I get is: No plugin found for prefix '.run.jvmArguments=-Xdebug -Xrunjdwp' – Alex Apr 03 '20 at 13:56
  • 2
    Thanks. It worked `mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dserver.port=8090 -Dspring.profiles.active=local"` spring-boot-maven-plugin=2.2.5.RELEASE – Haran Aug 05 '20 at 04:16
  • I have got the same error that Alex mentioned above when running it on Windows 11 – thangchung Dec 01 '21 at 05:33
  • @Alex running the command in IntelliJ I had the same "No plugin found for prefix..." error, but it works for me from command line. – Balazs F. Oct 26 '22 at 07:25
  • mvn spring-boot:run "-Dspring-boot.run.jvmArguments=-Dserver.port=8080" - It's work for me (Spring-boot - 3.0.1) – skyho Dec 28 '22 at 08:33
51

The behavior and the change you notice is happening because you started using the jvmArguments option:

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.

By default, when using it, the Spring Boot Maven plugin will also fork its execution, as described by the fork option:

Flag to indicate if the run processes should be forked. By default process forking is only used if an agent or jvmArguments are specified.

Hence, the usage of jvmArguments also activated the fork mode of the plugin execution. By forking, you are actually not picking up the others -D arguments passed from command line.

Solution: if you want to use the jvmArguments, then pass all of the required arguments to it.

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787 -Dserver.port=9090 -Dpath.to.config.dir=/var/data/my/config/dir"

-- Edit 22/09/2020 Check also the other answer from @Stephane to complent this answer (prefix of parameters)

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • 1
    Note: This worked, but I found that the -Drun.profiles option (and I'd guess other options starting with 'run') need to be kept *outside* the jvmArguments bit. eg: mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Dspring.foo=bar" -Drun.profiles=test – Ryan Apr 20 '17 at 04:05
  • Can you direct me to an in-depth document how this stuff works? – powder366 Nov 08 '17 at 10:09
  • @powder366 did you already try with the official documentation, already pointed by the answer above? There are examples and description of goals/options. Do you refer to Spring Boot specific documents or to more generic Maven-level documents? – A_Di-Matteo Nov 08 '17 at 10:16
  • 1
    I can debug starting the Spring application, running it with the mvn spring boot plugin I can't breakpoint. I like to understand how debugging works under the hood so I can make sense of it all... therefore looking for some nice articles about it. – powder366 Nov 08 '17 at 10:22
  • Super helpful. Thank you. – Laran Evans Nov 11 '17 at 01:06
26

Notice that from Spring Boot 2.0.2 names have changed. For more details check out:

Therefore:

  • run.jvmArguments -> spring-boot.run.jvmArguments
  • run.arguments -> spring-boot.run.arguments
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
jalogar
  • 1,604
  • 19
  • 27
2

Following redhat documentation ..

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$PORT_NUMBER"
2

Override spring-boot properties from Maven command line using Powershell:

  • Spring Boot 2.4.4
  • Maven 3.6.3
  • Powershell Windows 10

This worked for me:

mvn spring-boot:run  -D"spring-boot.run.jvmArguments"="-Dimport.dataset.list=importpb"
ssimm
  • 1,908
  • 3
  • 16
  • 36
0

One more issue is there. If pom.xml defines jvmArguments then command line arguments are ignored

<plugin>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <jvmArguments>-Xmx2048m -XX:NativeMemoryTracking=summary --enable-preview</jvmArguments>
        </configuration>
</plugin>

If I would like to add debug properties to one of launchers

-Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8282"

It is not gonna work.

simar
  • 1,782
  • 3
  • 16
  • 33