How do I use environment variables in an Eclipse .classpath file?

烂漫一生 提交于 2019-12-10 01:49:49

问题


In Windows I have an environment variable EXTERNAL_LIB_ROOT that points to C:\Program Files\MyExternalLibRoot. On another machine, it may point to C:\ExternalLibs.

In an ant build.xml file I would use:

<pathelement location="${env.EXTERNAL_LIB_ROOT}/path/to/jar.jar"/>

How do I set up an Eclipse project .classpath file to use the EXTERNAL_LIB_ROOT environment variable? Is it possible to have Eclipse auto generate the build.xml file using the environment variable as above?


回答1:


Not an environment variable, but you can set up a Path Variable in Eclipse. Path variables are per-workspace. They are therefore a convenient way of sharing a common location among multiple projects within a workspace. I have used them to share a lib folder among projects.

To create a Path Variable (either for the first time, or to re-use an existing one in a project):

  • File / New / Folder
    • Opens the New Folder dialog
  • Click on the Advanced button
  • Select the "Link to folder in the file system" check box
  • Click the Variables button
    • Opens the Select Path Variable dialog
  • Select or create a Path Variable

In your case, create a variable called EXTERNAL_LIB_ROOT.

(BTW, rather than generating a build.xml from your .classpath, I would suggest instead creating .classpath and .project from your build.xml.)




回答2:


Maybe the Ant addon Ant4Eclipse will help you, see
http://www.ant4eclipse.org/userguide-jdt and jdtClassPathVariable



来源:https://stackoverflow.com/questions/7742015/how-do-i-use-environment-variables-in-an-eclipse-classpath-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!