Launch mac eclipse with environment variables set

后端 未结 8 1535
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 00:16

My company provides an eclipse based development environment which needs some environment variables setting up for the underlying toolchain so multiple versions can be insta

相关标签:
8条回答
  • 2020-11-29 00:38

    There is an alternate solution which involves replacing the executable that is run by MacOS X when the user launches the Eclipse application with a shell wrapper that sets up the environment.

    Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/eclipse/Eclipse.app/Contents/MacOS.

    Open the eclipse.sh in a text editor an enter the following contents:

    #!/bin/sh
    
    export ENV_VAR1=value
    export ENV_VAR2=value
    
    logger "`dirname \"$0\"`/eclipse"
    
    exec "`dirname \"$0\"`/eclipse" $@
    

    In the example ENV_VAR1 and ENV_VAR2 are the environment variables being set up. These variables will be visible to processes launched from within Eclipse. The logger command will just log the path of the eclipse executable to the system.log as a debugging aid.

    In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:

    chmod +x /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.sh
    

    Open the Eclipse.app Info.plist and change the value for the key CFBundleExecutable from eclipse to eclipse.sh.

    MacOS X does not automatically detect that the Eclipse.app's Info.plist has changed. Therefore you need to force update the LaunchService database in the Terminal by using the lsregister command:

    /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app
    

    The next time you launch Eclipse.app from the Dock or from the Finder the environment variables should be set.

    0 讨论(0)
  • 2020-11-29 00:40

    sakra's answer above is awesome, except is doesn't automatically inherit your existing bash environment. To ensure eclipse.sh picks up your existing bash environment, modify eclipse.sh to use bash instead of sh and add a line to source your existing ~/.bash_profile thus:

    #!/bin/bash
    source ~/.bash_profile
    logger "`dirname \"$0\"`/eclipse"
    exec "`dirname \"$0\"`/eclipse" $@
    
    0 讨论(0)
提交回复
热议问题