How to set environment variables to an application on OSX Mountain Lion?

梦想的初衷 提交于 2019-11-27 12:28:32
Steve HHH

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.

Ashutosh Jindal

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.

You can set env variable directly in eclipse under maven "Debug Configurations" -> "Environment" tab

abhay anand

Steps of commands on terminal window:

  1. vi ~/.bash_profile
  2. Press i (to bring the vi editor in edit mode)
  3. Enter the environment variable in the vi editor window
    • e.g. export JAVA_HOME=/Users/Shared/Jenkins/Home/tools/hudson.model.JDK/java8
  4. esc key followed by :wq
  5. source ~/.bash_profile
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!