问题描述
在我的 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 选项"中使用环境变量和“程序参数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!