[ACCEPTED]-Launch mac eclipse with environment variables set-environment-variables

Accepted answer
Score: 47

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

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

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


export ENV_VAR1=value
export ENV_VAR2=value

logger "`dirname \"$0\"`/eclipse"

exec "`dirname \"$0\"`/eclipse" $@

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

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

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

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

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

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

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

Score: 8

I created the following:

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

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

Score: 6

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

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

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

Score: 4

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 16 the right side delete the "cat" that gets 15 put there automatically, and replace it 14 with this:

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

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

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

Score: 3

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

source ~/.bash_profile
logger "`dirname \"$0\"`/eclipse"
exec "`dirname \"$0\"`/eclipse" $@
Score: 3

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

See screenshot:

enter image description here

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

Score: 1

Link to Eclipse doesn't use the path set in .bashrc

  1. Create simple script
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"

2. Next put your all system variables 4 in file /home/user/.environment_variables 3 (any file you want)

My looks like:

export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

3. Now 2 you can delete your variables in .bashrc 1 and put line

source /home/user/.environment_variables

Everything works fine :)

Score: 1

As pointed out in https://github.com/atom/atom/issues/7045, the environment variables 4 can be loaded automatically, without explicit 3 source ~/.bash_profile by using

#!/usr/bin/env bash -l

instead of

source ~/.bash_profile

after that, in both 2 cases, follows

exec "`dirname \"$0\"`/eclipse" $@

It works great for me, thanks 1 for all previous work.

Score: 0

After setting env variables in .bash_profile. Simply 1 open the application through terminal!

open /Application/{path/to/app}.app

More Related questions