7

In Eclipse, it is possible to set environment variables using "run configurations", but this works only for a specific main program.

I have many different main programs in the same project, and I want to set the same environment variables in all of them. What is the easiest way to do this?

Erel Segal-Halevi
  • 33,955
  • 36
  • 114
  • 183

2 Answers2

2

You can create and set variables globally in Eclipse via the String Substitution form. The form is found via Preferences->Run/Debug->String Substitution.

Variables declared in the form can be used by referencing them with ${variable_name}.

More information about string substitution can be found here

HAL
  • 2,011
  • 17
  • 10
  • OK, but I still have to set the variables to ${variable_name} for every main program separately? – Erel Segal-Halevi Mar 12 '14 at 06:29
  • Yes, for every program/run configuration you will have to set the environment variables so that they use the variables from the string substitution form. By having a setup like that, it is easy to change a variable value and let all run configurations use that change without updating them. – HAL Mar 12 '14 at 07:54
2

What I usually do for a global environment variable is usually set it at the OS level. I do not know if there is a way in Eclipse to set global environment variables.

Christopher Z
  • 899
  • 1
  • 12
  • 32
  • How exactly do you do this at the OS level? I put some environment variables in "/etc/environment", rebooted my computer, verified that the variables exist (in a shell), but, in Eclipse they were not found... – Erel Segal-Halevi Mar 12 '14 at 06:43
  • This depends on the OS. In linux, that would usually be the `/etc/environment`. There is a similar post http://stackoverflow.com/questions/7048216/environment-variables-in-eclipse. Hope that answers your question. However, I have a feeling that you are using a Mac. So this other post may be more relevant (http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/588442#588442) – Christopher Z Mar 13 '14 at 00:35