Java Maven spring boot 带参数运行调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36217949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven spring boot run debug with arguments
提问by wbk
Usually I'm running my Spring Boot application with command:
通常我使用以下命令运行我的 Spring Boot 应用程序:
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 http://docs.spring.io/spring-boot/docs/1.1.2.BUILD-SNAPSHOT/maven-plugin/examples/run-debug.html
我想设置自定义端口进行调试,所以我可以从 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"
it works but other arguments like server.port
or path.to.config.dir
are no longer recognized and I get exception like:
它有效,但其他参数如server.port
或path.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"
Question: How I can run with all arguments?
问题:我如何使用所有参数运行?
采纳答案by A_Di-Matteo
The behavior and the change you notice is happening because you started using the jvmArguments
option:
您注意到的行为和变化正在发生,因为您开始使用该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.
应与用于运行应用程序的分叉进程相关联的 JVM 参数。在命令行上,确保在引号之间包含多个值。
By default, when using it, the Spring Boot Maven plugin will also fork its execution, as described by the fork
option:
默认情况下,在使用它时,Spring Boot Maven 插件也会分叉其执行,如fork
选项所述:
Flag to indicate if the run processes should be forked. By default process forking is only used if an agent or
jvmArguments
are specified.
用于指示是否应分叉运行进程的标志。默认情况下,进程分叉仅
jvmArguments
在指定代理或指定时使用。
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.
因此,使用jvmArguments
也激活了插件执行的 fork 模式。通过分叉,您实际上并未-D
获取从命令行传递的其他参数。
Solution: if you want to use the jvmArguments
, then pass all of the required arguments to it.
解决方案:如果要使用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"
回答by jalogar
Notice that from spring-boot 2.0 names have changed. For more details check out:
请注意,从 spring-boot 2.0 开始,名称已更改。有关更多详细信息,请查看:
https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/maven-plugin/run-mojo.html
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
- run.jvmArguments-> spring-boot.run.jvmArguments
- run.arguments-> spring-boot.run.arguments
回答by Stephane
The parameter name has to be prefixed with spring-boot.
as in -Dspring-boot.run.jvmArgument
参数名称必须以spring-boot.
as in为前缀-Dspring-boot.run.jvmArgument
The Spring Boot documentationprovided me the solution as I'm running Spring Boot 2.0.3
在春季启动文档,因为我跑给我提供解决方案Spring Boot 2.0.3
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"