0

In Ubuntu I have exported the below environment variable in ~/.bashrc:

export MY_VAR="MY_VAR_VALUE"

When I re-open a terminal I can do:

~ $ echo $MY_VAR
MY_VAR_VALUE
~ $ 

But when I do this in Java/Eclipse (which I have restarted after exporting the test env. var):

String myVar = System.getenv("MY_VAR");
System.out.println(myVar);

I just get null. Does eclipse not see variables set in ~/.bashrc ?

2
  • 3
    Depends on how you start Eclipse. Is it running from a script or console that has your Bash environment set? Try running the Java program directly from a Bash prompt. Commented Jul 16, 2016 at 20:46
  • 1
    it doesn't see variables set in ~/.bashrc. You must pass by the shell or create a script which export variables and launch eclipse Commented Jul 16, 2016 at 20:52

1 Answer 1

2

In Linux (unlike Windows) you need a direct child relatinship between the Java executable, started by Eclipse, started by the Shell where you have exported the variable.

So you must start Eclipse from within that Shell. It wont work if you doubleclick on the executable in desktop or menu.

But I would specify the environment variables you need in the run configuration and not rely on such a setup.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.