since the upgrade to OSX Mountain Lion I‘ve got some problems with setting the environment variables for eclipse and maven.
My goal is to run a maven command in Ecli
Unfortunately, this seems to be the best option for setting a global environment variable in OS X 10.8.x Mountain Lion:
For temporary environment variables, run this command in Terminal.app, and restart any apps that need to access the variable:
launchctl setenv MYVARIABLE value
To make an environment variable persistent across reboots, create /etc/launchd.conf
and add a line like this for each variable, then reboot your entire system:
setenv MYVARIABLE value
This worked for me to set a global environment variable that could be inherited by IntelliJ IDEA CE 12.0 on OS X 10.8.2. Not very elegant, but it works.
Alternatively, you can set the environment variable in Terminal.app, then launch the App from which you want to access the environment variable from the command-line. The launched app will inherit the environment from your terminal session. In Terminal.app, set the environment variable and launch another app with a command like open -a "App Name"
:
export MYVARIABLE=value
open -a "IntelliJ IDEA 12 CE"
This opens IntelliJ IDEA, and my code can access $MYVARIABLE
in its environment.
You can set env variable directly in eclipse under maven "Debug Configurations" -> "Environment" tab
From here : https://stackoverflow.com/a/10374886/325742
#!/bin/sh
#
export MAVEN_OPTS=#MAVEN_OPTS_HERE#
LAUNCHER_JAR=/Applications/eclipse/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
java \
-showversion \
-XX:MaxPermSize=256m \
-Xms1024m \
-Xmx1024m \
-Xdock:icon=/Applications/eclipse/Eclipse.app/Contents/Resources/Eclipse.icns \
-XstartOnFirstThread \
-Dorg.eclipse.swt.internal.carbon.smallFonts \
-Dosgi.requiredJavaVersion=1.5 \
-jar $LAUNCHER_JAR
Then, use the steps on http://mathiasbynens.be/notes/shell-script-mac-apps, to turn the above script into an application that can be kept on the dock.
Steps of commands on terminal window: