在"VM选项"中使用环境变量.和“程序自变量" [英] Using environment variables in "VM options" and "Program arguments"
问题描述
在IDEA中的项目配置中,我具有以下文本字段:
In my project configuration in IDEA, I have the following text fields:
我想定义一些环境变量,并在字段"VM options"
和"Program arguments"
中引用它们.
I would like to define some environment variables, and refer to them in the fields "VM options"
and "Program arguments"
.
我尝试使用以下环境变量定义:
I tried with the following definitions for environment variables:
MY_FOLDER=/some/random/path
MY_ARGUMENT=2
,然后在"VM options"
中输入:
-Dfoo=$MY_FOLDER
在我输入的程序参数中
$MY_ARGUMENT foo bar
但是,在调用我的类之前,环境变量似乎没有被解析,即,如果我在Java中检查args[0]
,则它包含字符串值$MY_ARGUMENT
,不是 2
.
However, the environment variables do not seem to be resolved prior to calling my class, i.e. if I inspect args[0]
in Java, it holds the string value $MY_ARGUMENT
, not 2
.
为什么?以及我该如何解决?
Why? and how can I fix this?
推荐答案
您可以使用括号括起来的环境变量语法访问环境变量.示例:
You can access environment variables using the brace-enclosed environment variable syntax. Example:
VM选项:-Dfoo=${MY_ENV_VAR}
MY_ENV_VAR
环境变量将正确展开.
MY_ENV_VAR
environment variable will be expanded properly.
更新:已在IntelliJ IDEA 2017.1.2中进行了测试,并且仍在运行.
Update: tested in IntelliJ IDEA 2017.1.2 and still working.
这篇关于在"VM选项"中使用环境变量.和“程序自变量"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!