Ashwin
Ashwin

Reputation: 13547

System.getenv() call in JVM

I am setting environment variable in my machine using export MY_KEY=foo. And I am trying to fetch it in JVM using System.getenv("MY_KEY"). This returns null. But running echo $MY_KEY shows foo on the terminal.
I have tried restarting the IDE. Doesn't work, still.

Upvotes: 1

Views: 252

Answers (1)

Ralph Löwe
Ralph Löwe

Reputation: 424

The environment variable is only available to sub processes of the shell that exported it. Did you start your IDE from that shell?

If you want the variable to be available all the time, you need to add it to the /etc/profile file or create a extra file in /etc/profile.d. It depends on your operating system.

Upvotes: 3

Related Questions