简体   繁体   中英

System.getenv() not finding environment variables on Eclipse (Mac)

I tried doing everything but my environment variables are just not recognized on Mac.

The image is attached below.

在此处输入图片说明

System.getenv("TEST_LOGIN_DBKEY") returns null although the variable is present.

You need to use launchctl to tell eg, Eclipse about these variables.

launchctl setenv TEST_LOGIN_DBKEY key-goes-here

You can automate this and extend it to all your bash environment variables by placing the following at the bottom of your ~./bashrc :

set | sed 's/=/ /' | xargs launchctl setenv

The set prints the list of defined variables, the sed replaces equals signs in the set output with spaces, as that's how launchctl expects the variables. Finally, xargs passed each variable to launchctl 's set env command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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