Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

java - Using environment variables in "VM options" and "Program arguments"

In my project configuration in IDEA, I have the following text fields:

Project configuration

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

and then in "VM options" I entered:

-Dfoo=$MY_FOLDER

and in program arguments I entered

$MY_ARGUMENT foo bar

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can access environment variables using the brace-enclosed environment variable syntax. Example:

VM options: -Dfoo=${MY_ENV_VAR}

VM options

MY_ENV_VAR environment variable will be expanded properly.

Update: tested in IntelliJ IDEA 2017.1.2 and still working.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...