Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Environment Variable At Eclipse workspace level for all launchers?

Can I set a workspace wide setting to add an environment variable to all future launchers created in the workspace?

Use Case

  • Our unit tests require an environment variable to guide the test to certain resources.
  • the variable varies with each version of our product

Options - modify each junit launcher with the environment variable - create start up script that sets variable and launches eclipse - set globally

Ideally, I'd like to provide a way for users to set it once per workspace.

Does eclipse have a place to set an environment variable for all launchers?

Thanks

Peter

like image 521
Peter Kahn Avatar asked Nov 15 '13 22:11

Peter Kahn


People also ask

How do I permanently set environment variables?

You can set an environment variable permanently by placing an export command in your Bash shell's startup script " ~/. bashrc " (or "~/. bash_profile ", or " ~/. profile ") of your home directory; or " /etc/profile " for system-wide operations.


2 Answers

Only option which I can think of is similar to yours where you can create multiple shell scripts(linux) or batch files(windows) and set it up there. for ex -

I am giving examples for windows environment and same can be done for Linux as well -

for windows-

eclipse.exe -DvariableName1=value1 -DvariableName2=value2

As you want to pass different variables to different workspaces, you can also pass location of your workspace as part of arguments.

eclipse.exe -data <your_workspace_location> -DvariableName1=value1 -DvariableName2=value2

You can create multiple shortcuts of eclipse.exe in windows and place them on Desktop (for quick access) if needed. Each shortcut may point to a similar variant of above command with different workspace and different variables.

Hope this helps. Happy coding :)

like image 106
Soman Dubey Avatar answered Nov 09 '22 08:11

Soman Dubey


I have a different approach for doing this on windows. This solution allows you to store a large number of environment variables to one place and apply them globally inside eclipse.

  1. I have gitBash installed already, and associated in windows to execute .bash files
  2. I set up a /c/Temp/.env file with lots of environment variables in the format

export VARIABLE=my value

  1. I create an eclipse_startup.bash script that looks like this (and pin it to my start menu).
echo setting up env
. /c/Temp/.env

echo starting eclipse
/c/Users/me/eclipse-oxygen/eclipse/eclipse.exe

It has the disadvantage that I end up with a bash window open with eclipse, and I have to restart after changing the environment. On the plus side, my complex application has lengthy environment files already, so I can simply load them in and start.

like image 34
Paul Cuddihy Avatar answered Nov 09 '22 08:11

Paul Cuddihy