简体   繁体   English

如何验证我的MAVEN_OPTS环境变量是否正在传递给正在启动的java进程?

[英]How can I verify that my MAVEN_OPTS environment variable is being passed to the java process being started?

I'm setting some options -Dmyflag=myvalue in MAVEN_OPTS. 我在MAVEN_OPTS中设置了一些选项-Dmyflag = myvalue。 I know this works based on other testing I've done (when using mvn spring-boot:run ) but a newly set value I'm using doesn't seem to be working. 我知道这可以基于我已经完成的其他测试(当使用mvn spring-boot:run时 ),但是我正在使用的新设置值似乎不起作用。

The first place to start is to make sure the option is being passed to the program being started by maven. 首先要确保将选项传递给maven启动的程序。 In my case, I'm running a unit test that dsdsneeds some options set on the command line. 就我而言,我正在运行一个单元测试,它需要在命令行上设置一些选项。

Is there a maven command that will show me the -Doptions that are being passed to the java commands that are started by Maven? 是否有maven命令将显示正在传递给由Maven启动的java命令的-Doptions?

NOTE: This may be an issue with the surefire plugin not passing MAVEN_OPTS when starting tests. 注意:这可能是surefire插件在启动测试时未通过MAVEN_OPTS的问题。

I've tried 我试过了

mvn -X clean install

and I see output that implies that a test is being started, the output is something like: 我看到输出暗示正在启动测试,输出类似于:

Forking command line: /bin/sh -c cd /my/proj && /usr/bin/java -jar /.../my.jar

And I don't see any options being passed so I'm guessing that the MAVEN_OPTS are not being passed to the unit test that is running. 我没有看到任何选项被传递,所以我猜测MAVEN_OPTS没有被传递给正在运行的单元测试。

Searching for answers I found these links: 寻找答案我找到了这些链接:

From mvn --help : 来自mvn --help

-D,--define Define a system property -D, - define定义系统属性

So anything you pass in with -D , you should be able to read back with System.getProperty("<arg>") . 所以你用-D传入的任何东西,都应该能够用System.getProperty("<arg>")读回来。

Alternatively, you can use mvn -X ... to see what is being passed: 或者,您可以使用mvn -X ...来查看传递的内容:

-X,--debug Produce execution debug output -X, - debug生成执行调试输出

As for your comment: 至于你的评论:

This may be an issue with the surefire plugin not passing MAVEN_OPTS when starting tests. 这可能是surefire插件在启动测试时未通过MAVEN_OPTS的问题。

From my own experiments, and I wish I had a citation for this, when tests are run - either with surefire or failsafe - they are run in a separate thread. 从我自己的实验中,我希望我有一个引用,当测试运行时 - 无论是使用surefire还是failafe-它们都在一个单独的线程中运行。 This new thread does not receive any properties from MAVEN_OPTS. 此新线程从MAVEN_OPTS接收任何属性。 However, it will receive properties passed on the command line with -D... 然而, 收到-D在命令行上传递的属性...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM