spinyBabbler
spinyBabbler

Reputation: 407

Setting environment variables on eclipse

I have been looking up ways to create a launcher of sorts so that environment variables are set when I run the Eclipse app on mac.

When I run the app from terminal, the environment variables are properly set since the bash script has them; however, when I run the app directly, it doesn't have them. I have looked at automator and eclipse settings but cannot seem to find a simple way of doing it. This is important because when I do maven install, the paths are not correct. I could set environment variables every time I do run but that seems tedious. Any ideas?

Upvotes: 2

Views: 1024

Answers (2)

robcast
robcast

Reputation: 495

You can also add the environment to the Info.plist and use lsregister if you don't want to swap the executable (found at SJGP software blog).

Add the following to the Info.plist file in the application bundle:

  <key>LSEnvironment</key>
  <dict>
    <key>GIT_SSH</key>
    <string>/usr/bin/ssh</string>
  </dict>

then run lsregister on the application:

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

Upvotes: 1

Richard Barber
Richard Barber

Reputation: 6431

You could have the .app call an executable loader script, which can set environment variables and call the executable binary. The script is placed in Contents/MacOS/. If you swap names with the main exec. binary, Info.plist will already point to it, then call the renamed binary from the loader script.

#!/usr/bin/env bash


cd "$(dirname "$0")" || exit 1

cwd="$(pwd)"
export VARIABLE=808
exec "${cwd}/myapp"

Upvotes: 1

Related Questions