在 IntelliJ 或 Eclipse 中设置 java 系统属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29454494/
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
Set java system properties in IntelliJ or Eclipse
提问by diegomontoyas
I have a project which runs correctly under the terminal command
我有一个在终端命令下正确运行的项目
mvn package exec:java -Dplatform.dependencies -Dexec.mainClass=Demo
Now, I need to debug it correctly (not terminal) with IntelliJ or Eclipse on Mac (preferably IntelliJ) but I have tried setting VM options in various places and nothing seems to work.
现在,我需要在 Mac(最好是 IntelliJ)上使用 IntelliJ 或 Eclipse(最好是 IntelliJ)正确调试它(不是终端),但我尝试在各个地方设置 VM 选项,但似乎没有任何效果。
Where is the correct place to put these options: -Dplatform.dependencies -Dexec.mainClass=Demo?
放置这些选项的正确位置在哪里:-Dplatform.dependencies -Dexec.mainClass=Demo?
回答by Mzf
In InteliJ goto "Run"->"Edit Configurations" In the new window, right panel, open the Junit and click on your test. Now, in the middle click on the "Configuration" tab and update the "VM options"
在 InteliJ 中,转到“运行”->“编辑配置” 在新窗口的右侧面板中,打开 Junit 并单击您的测试。现在,在中间单击“配置”选项卡并更新“VM 选项”
Note that you will need to do this for every test class, but you can remove all the test from the junit in the right panel and update it in the "Defaults"
请注意,您需要为每个测试类执行此操作,但您可以从右侧面板中的 junit 中删除所有测试并在“默认值”中更新它
回答by sanimalp
If you are like me, and showed up here trying to run tests that use the -P syntax instead of -D syntax, you can simply follow the instructions from MZF, but use the -D in place of the-P.
如果你像我一样,并试图运行使用 -P 语法而不是 -D 语法的测试,你可以简单地按照 MZF 的说明进行操作,但使用 -D代替-P。
For example, my test on the command line executed as:
例如,我在命令行上的测试执行为:
./gradlew -Penvironment=qa project:test
./gradlew -Penvironment=qa 项目:测试
Using the -P in intellij on the VM line got rejected. Changing the -P to a -D ended up working, however.
在 VM 行上的 intellij 中使用 -P 被拒绝。但是,将 -P 更改为 -D 最终起作用了。