I was trying to achieve this but in the context of a MAVEN build. As part of my pom.xml
configuration, I had a reference to an environment variable as part of a path to a local JAR:
<dependency>
<groupId>the group id</groupId>
<artifactId>the artifact id</artifactId>
<version>the version</version>
<scope>system</scope>
<systemPath>${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar</systemPath>
</dependency>
To compile my project, I had to define the environment variable as part of the run configuration for the maven build as explained by Max's answer. I was able to launch the maven compilation and the project would compile just fine.
However, as this environment variable involves some dependencies, the default "problems" view of Eclipse (where compilation errors/warnings usually show) would still show errors along the lines of Could not find artifact
and systemPath should be an absolute path but is ${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar
.
How I fixed it
Go into Window -> Preferences -> General -> Worksapce -> Linked Resources
and define a new path variable.
Finally, in my case I just needed to Right click on my pom.xml
file, select Maven -> Update Project
and the errors disappeared from the "Problems" view.