Maven spring boot使用参数运行调试

wbk*_*wbk 30 java spring maven-3 maven spring-boot

通常我用命令运行我的Spring Boot应用程序:

mvn spring-boot:run -Drun.arguments=--server.port=9090 \
   -Dpath.to.config.dir=/var/data/my/config/dir
Run Code Online (Sandbox Code Playgroud)

我想设置自定义端口进行调试,所以我可以从eclipse连接.当我从示例http://docs.spring.io/spring-boot/docs/1.1.2.BUILD-SNAPSHOT/maven-plugin/examples/run-debug.html添加参数时

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"
Run Code Online (Sandbox Code Playgroud)

它有效,但其他论点喜欢server.portpath.to.config.dir不再被认可,我得到例外:

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"
Run Code Online (Sandbox Code Playgroud)

问题:如何运行所有参数?

A_D*_*teo 33

您注意到的行为和更改正在发生,因为您开始使用该jvmArguments选项:

应与用于运行应用程序的分叉进程关联的JVM参数.在命令行中,确保在引号之间包装多个值.

默认情况下,使用它时,Spring Boot Maven插件也将执行分叉,如fork选项所述:

用于指示是否应分叉运行进程的标志.默认情况下,仅在代理或jvmArguments指定时才使用过程分叉.

因此,使用jvmArguments也激活了插件执行的fork模式.通过分叉,您实际上并没有-D获取从命令行传递的其他参数.

解决方案:如果要使用jvmArguments,则将所有必需的参数传递给它.

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"
Run Code Online (Sandbox Code Playgroud)


Ste*_*ane 16

参数名称必须以spring-boot.in 为前缀-Dspring-boot.run.jvmArgument

春季启动文档,因为我跑给我提供解决方案Spring Boot 2.0.3

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Run Code Online (Sandbox Code Playgroud)

  • 这个答案适用于大多数人,但它在 PowerShell 中不适用于我,我得到的消息是: No plugin find for prefix '.run.jvmArguments=-Xdebug -Xrunjdwp' (7认同)
  • 这应该是公认的答案,其他答案不起作用 (5认同)
  • 谢谢。它有效 `mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dserver.port=8090 -Dspring.profiles.active=local"` spring-boot-maven-plugin=2.2.5.RELEASE (3认同)

jal*_*gar 15

请注意,从spring-boot 2.0名称已更改.有关详细信息,请查看:

https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/maven-plugin/run-mojo.html

  • run.jvmArguments - > spring-boot.run.jvmArguments
  • run.arguments - > spring-boot.run.arguments