Setting Environment Variables with Spaces in OS X 10.8 (Mountain Lion)…

For setting the PATH and other environment variables, see here, since it will explain the more appropriate place for them.

Unfortunately, the methods listed in the linked article above don’t work for environment variables with spaces, e.g. MAVEN_OPTS="-Djavax.net.ssl.trustStore=keystore -Djavax.net.ssl.trustStorePassword=password".

To set these, the variables have to be configured as launch daemon arguments.  Here is an example of a file I have:

$ cat /Library/LaunchDaemons/mavenopts.plist
<?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>Label</key>
	<string>MAVEN_OPTS</string>
	<key>ProgramArguments</key>
	<array>
		<string>launchctl</string>
		<string>setenv</string>
		<string>MAVEN_OPTS</string>
		<string>-Djavax.net.ssl.trustStore=keystore -Djavax.net.ssl.trustStorePassword=password</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>KeepAlive</key>
	<true/>
	<key>LaunchOnlyOnce</key>
	<true/>
</dict>
</plist>

This file can also go in /System/Library/LaunchDaemons instead of /Library/LaunchDaemons, but this is more a matter of philosophy; either location will work.

For more details, here is the Apple documentation: http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html#//apple_ref/doc/uid/10000172i-SW7-BCIEDDBJ