MacOSXEnvForApp

How to define environment variables so that Mac OS X applications can see them.

Installed Mac OS X applications do not see unix environment variables defined in ~/.cshrc or any other of the standard unix configuration files. But installed NetBeans on Mac OS X may use of environment variables. To get them visible, you should define your environment variables in the file ~/.MacOSX/environment.plist. You will almost certainly have to create the directory and the file yourself. The format is as per this example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>SCALA_HOME</key>
	<string>full/path/of/your/scala/home</string>
	<key>PATH</key>
	<string>/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/full/path/of/your/scala/home/bin</string>
</dict>
</plist>

Warnings:

  • Whenever you modify environment.plist, you must log out and then log back in again to see the changes.
  • Use absolute paths and spell them out. The home directory shortcut ~ is not expanded.
  • Be careful if you define an environment variable both in environment.plist and in .cshrc (or any other config file that is read when Terminal starts up). The definition in .cshrc will override (i.e. supersede, shadow, replace) the definition in environment.plist when using the Terminal. This often bites people defining PATH.
  • It may be necessary for the file to have unix line endings. I haven't tried anything else.

Notes:

If you have Apple's developer tools installed then you can create and edit this file using /Developer/Applications/PropertyListEditor.app. For the official word on this file, see Apple's Technical Q&A QA1067.

At least in Snow Leopard, 10.6, the executable PlistBuddy is available. You can include the following in your .profile for settting both terminal environment and environment.plist. The functions take two arguments: <env var name> <env var value>


set_env_var () {
    eval export $1="$2"
    set_plist_var "$1" "$2"
}

set_plist_var () {
    PlistBuddy -c 'Delete :'"$1" ~/.MacOSX/environment.plist
    PlistBuddy -c 'Add :'"$1"' string "'"$2"'"' ~/.MacOSX/environment.plist
}

There is a good thread with some additional information on setting up Java on Mac OS at http://lists.apple.com/archives/java-dev/2008/Aug/msg00176.html
\



\ For more documentation about using NetBeans on Mac OS X, see NetBeansMacOSX


This no longer works as Apple has discontinued environment.plist in OSX Lion. The only way i have found to make the Scala plugin work is to add export SCALA_HOME=<your scala home> to the netbeans/etc/netbeans.conf file.


For me in OSX Lion only works defining SCALA_HOME at /Applications/NetBeans/NetBeans 7.0.app/Contents/Resources/NetBeans/bin/netbeans

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo