Search code examples
javaenvironment-variablessystem-variable

System.getenv("TEST_HOME") is returning null


I am working on a ubuntu 14.0.4 machine.

I exported a variable TEST_HOME in my .bashrc file using

export TEST_HOME=/home/dev/code/test

When I tried echo $TEST_HOME from terminal, it returned /home/dev/code/test

So far, so good.

When I try from Java code :

String value = System.getenv("TEST_HOME");

value is null.

Am I missing something here?


Solution

  • Mentioning the variable in .bashrc will work only for programs started from shell. For system wide environment variables mention it in /etc/environment.

    Refer Ubuntu Environment variables