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

前端 未结 4 1994
南旧
南旧 2020-12-03 00:13

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

相关标签:
4条回答
  • 2020-12-03 00:34

    Unfortunately, this seems to be the best option for setting a global environment variable in OS X 10.8.x Mountain Lion:

    • https://stackoverflow.com/a/588442/705157

    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.

    0 讨论(0)
  • 2020-12-03 00:36

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

    0 讨论(0)
  • 2020-12-03 00:41

    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.

    0 讨论(0)
  • 2020-12-03 00:50

    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
    0 讨论(0)
提交回复
热议问题