Friday, November 27, 2009

Mac OS X environment variables + Netbeans + Maven

Applications that are not launched through your terminal in OS X do not read environment variables from ~/.profile, ~/.bash_profile and similar. These applications that launch directly can get their environment from each user's ~/.MacOSX/environment.plist file. ( You have to create it!)

I heard of this before, but I wanted to make note of a quick way to ease the maintaining of that file and finally had a need because of Netbeans.
  1. Downloaded Brian D Foy's Perl plist lib and installed it.
  2. Used a 3 line script to generate the ~/.MacOSX/environment.plist file from my terminal's ENV variable as he suggested.
  3.  Log out and log in for the file to take effect.
Now I can be sure the PATH that Netbeans sees is the same thing that mvn and other tools are seeing when I execute them on the cmd line. Also I don't really have to worry about maintaining my env in two places as one is derived from the other.

References
Technical Q&A QA1067: Setting environment variables for user processes
Helpful Summary of other ways to set env variables in OS X
Brian D Foy's Perl plist reader lib and blog post
Netbeans documentation on working with OS X Environment variables

Update
Another method is setting environment variables inside your
/etc/launchd.conf
file as described here - there are clear benefits to this for apps launched outside your personal login.

No comments:

Post a Comment