Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch mac eclipse with environment variables set

People also ask

How do I permanently set environment variables on Mac?

Set an Environment Variable — temporary or permanent Otherwise, you can have it permanently in Bash Shell Startup Script with “Export” command. And then close the terminal window and open another one to check out if the set variable has disappeared or not.

How can I see environment variables in Eclipse?

Use the target icon (at the top of Process Explorer) and click on the Eclipse window which will select the Eclipse Process ID in the Process table. Right-click on the selected Eclipse entry and select Properties... from the context menu. Click on Environment.


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.


I created the following:

alias start-eclipse='open /Applications/eclipse/Eclipse.app'

If you run start-eclipse from the command line, all env vars will be picked up. This way, you only need to maintain a single set of env vars across both command-line and eclipse environments.


Take a look at a related question: Environment variables in Mac OS X.

Basically, this involves the creation of a ~/.MacOSX/environment.plist file.

Log out and Log in for the environment.plist to get picked up by .App's


This worked perfectly in OS X Yosemite:

  1. Open /Applications/Automator.
  2. When the drop-down appears asking you what kind of document you want to create, choose "Application."
  3. In the second-from-the-left list, double-click "Run Shell Script."
  4. In the right side delete the "cat" that gets put there automatically, and replace it with this:

    source ~/.bash_profile && /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse
    

Now go to File->Save, and save the application to your Applications directory. I named it "Eclipse" with a capital 'E' so as not to conflict with the "eclipse" directory I already had. For good measure, you can even give it the Eclipse icon by selecting the real eclipse app, pressing command-i, selecting the icon, pressing command-c, then selecting the automator "Eclipse" app, pressing command-i, selecting the icon, and pressing command-v.

Now you can open the app, or even drag it to your dock. Note that if you start it, the "real" eclipse will still show up in your dock as a separate icon, but you can't have everything. :)


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" $@

None of the above worked for me. you have to set Eclipse -> Preferences -> Terminal -> Arguments set to --login That will instruct Eclipse to login with your account just after opening Terminal.

See screenshot:

enter image description here

Reference: https://marketplace.eclipse.org/comment/4259#comment-4259