简体   繁体   English

Java程序无法获取环境变量mac

[英]Java program not able to pick up environment variables mac

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 伊夫看着几个相关链接,例如这个 ,但我的java程序不能似乎回暖中定义的环境变量/.bashrc/.bash_profile

Here's my bash_profile (bashrc is the same) 这是我的bash_profile (bashrc是相同的)

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 Shell在eclipse中:

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. 任何见解或链接将不胜感激。

.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. 蚀启动程序时将不考虑.bashrc.bash_profile因为这些文件是为交互式外壳程序使用的设置而设计的。

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 : 另一种方法包括创建文件(或编辑,如果已经存在) /etc/launchd.conf并在该文件中设置变量,例如:

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 请注意,这是用于OSX(OP的OS),但是对于普通Linux,您可以编辑/etc/environment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM