4

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?

4

2 回答 2

8

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

于 2016-03-30T07:00:55.020 回答
1

.bashrc would set environment variable only for bash shell. To set it system wide set it in /etc/environment file.

Since you are using eclipse, and it does not run within bash shell, it is not getting the variable you are setting. If you run your programme using java command line in your terminal then it should get it.

Setting variable in /etc/environment would make it available to eclipse. You will need to restart your machine once you update /etc/environment.

于 2016-03-30T07:08:45.460 回答