I am developing an Eclipse Java project and would like to use "variables" to point to required libraries (.jar files).
Setup:
- Machine 1: Eclipse Juno, OS X, own laptop, libs under
/mylibs
- Machine 2: Eclipse Juno, Linux, shared machine, libs under
/sharedlibs/some/complex/path
Source control: Mercurial
Example of libs I use:
- "${libs_base}/junit.jar"
- "${libs_base}/guava.jar"
- "${libs_base}/logging/slf4j.jar"
How can I configure the project Build Path
to use the same "variable" for the base directory for libraries, pointing to different locations on different machines, but still check in my project description to source control so that when I add a new library, provided I specify its location relative to the libs base, it is found on both machines?
I have found the help file but could use an example, maybe even a screenshot please?
for instance, do I copy this model:
inside "Java > Build Path > Classpath Variables" or elsewhere?
I have done a fair bit of "blind trial and error" already.. like stitching forms like "${env:VAR}" in there..
Oh, and I suppose I should mention that I don't know how to set these Eclipse variables based on environment variables considering that my systems' environment variables are set by Bash's .profile
and I doubt Eclipse runs a shell to source that before…
/org.eclipse.jdt.core/org.eclipse.jdt.core.classpathVariable.my_libraries=$MY_SYS_ENV_VAR_LIBS
Of course, I use "Configure Build Path > Libraries > Add Variable" and then Extend from there, but still… an example would be worth a 1000 words.. (could it be that defining an Eclipse variable from which to Extend
actual .jar references for inclusion in Build Paths just can't be based on a system environment variable, full stop?!)
PS: please don't ask me to just symlink things around, I am not a sysadmin on the shared machine..
Best Answer
From what I understand, extending a path variable would work perfectly for your case as you can define different base paths for each machine and reference libraries on subpaths based on that path. However if you are looking specifically to use environment variables you can try adding them to the build path this way:
${env_var:libs_base}/logging/slf4j.jar
. In this caselibs_base
is your environment variable andlogging/slf4j.jar
is the path to the jar in the subdirectory.