1

Ive looked at several related links such as this but my java program cant seem to pick up an environment variable defined in /.bashrc, /.bash_profile

Here's my bash_profile (bashrc is the same)

export JBOSS_HOME=/Applications/whp-jboss-cluster-5
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/
export FDP_HOME=/Users/kodeseeker/Project/git_intuit/
export TOMCAT_HOME=/Library/Tomcat/
export GIT_HOME=/Users/kodeseeker/Project/git_intuit
export MULE_HOME=/usr/local/mule/mule-enterprise-standalone-3.6.0-M2



echo $MULE_HOME returns 
/usr/local/mule/mule-enterprise-standalone-3.6.0-M2 as well. 

But printing

 Map<String, String> env = System.getenv();
        for (String envName : env.keySet()) {
            System.out.println(
                              envName + " "+ 
                              env.get(envName));
        }
        System.out.println("****");
        System.out.println(env.get("MULE_HOME"));// returns null. 

Both use the same shell Shell in eclipse from output :

SHELL /bin/bash
APP_ICON_12441 ../Resources/Eclipse.icns
TMPDIR /var/folders/jc/bpc8py6s47jftq8mny923n4r5jfsj2/T/

echo $SHELL
/bin/bash

I've tried logging out, restarting the terminal etc. but with no avail. Any insight or links would be appreciated.

3
  • 1
    Have you checked whether the variable is available in the shell that you're running this from? What does echo $MULE_HOME print? Commented Jan 29, 2015 at 23:13
  • Yup. Same shell . Should have added that as well. Commented Jan 29, 2015 at 23:13
  • You are running the code from JBoss right ? Commented Jan 29, 2015 at 23:19

1 Answer 1

2

.bashrc or .bash_profile won't be taken in consideration when eclipse start the program as these files are designed for settings used by interactive shells.

To make your variable visible to eclipse, navigate to

Run -> Run Configuration

Select the tab Environment, and add your variable.

Another way would consist of creating a file (or edit if it already exists) /etc/launchd.conf and set the variable in this file for example :

setenv MY_VARIABLE MY_VALUE

Don't forget to reboot.

Note that this is for OSX (OP's OS), but for normal Linux, you can edit /etc/environment

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.