Skip to content

Maven spring boot run debug with arguments

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

mvn spring-boot:run -Drun.arguments=--server.port=9090

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

mvn spring-boot:run -Drun.arguments=--server.port=9090 
   -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787"

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

org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class []; nested exception
is java.lang.IllegalArgumentException: Could not resolve placeholder
'' in string value

Question: How I can run with all arguments?



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"

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