如何在 Eclipse .classpath 文件中使用环境变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7742015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use environment variables in an Eclipse .classpath file?
提问by user991650
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.
在 Windows 中,我有一个指向 C:\Program Files\MyExternalLibRoot 的环境变量 EXTERNAL_LIB_ROOT。在另一台机器上,它可能指向 C:\ExternalLibs。
In an ant build.xml file I would use:
在 ant build.xml 文件中,我会使用:
<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?
如何设置 Eclipse 项目 .classpath 文件以使用 EXTERNAL_LIB_ROOT 环境变量?是否可以使用上述环境变量让 Eclipse 自动生成 build.xml 文件?
回答by sudocode
Not an environment variable, but you can set up a Path Variablein 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.
不是环境变量,但您可以在 Eclipse 中设置路径变量。路径变量是每个工作区的。因此,它们是在工作空间内的多个项目之间共享公共位置的便捷方式。我用它们在项目之间共享一个 lib 文件夹。
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.
在您的情况下,创建一个名为 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.)
(顺便说一句,我建议不要从您的 .classpath 生成 build.xml,而是从您的 build.xml 创建 .classpath 和 .project。)
回答by Rebse
Maybe the Ant addon Ant4Eclipsewill help you, see
http://www.ant4eclipse.org/userguide-jdtand jdtClassPathVariable
也许 Ant 插件Ant4Eclipse会帮助你,见
http://www.ant4eclipse.org/userguide-jdt和jdtClassPathVariable