使用变量的 Eclipse Java 项目构建路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13904970/
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
Eclipse Java project build path using variables
提问by Robottinosino
I am developing an Eclipse Java project and would like to use "variables" to point to required libraries (.jar files).
我正在开发一个 Eclipse Java 项目,并希望使用“变量”来指向所需的库(.jar 文件)。
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
- 机器 1:Eclipse Juno,OS X,自己的笔记本电脑,libs 下
/mylibs
- 机器2:Eclipse Juno,Linux,共享机器,libs下
/sharedlibs/some/complex/path
Source control: Mercurial
源代码控制:Mercurial
Example of libs I use:
我使用的库示例:
- "${libs_base}/junit.jar"
- "${libs_base}/guava.jar"
- "${libs_base}/logging/slf4j.jar"
- “${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 basedirectory 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?
如何将项目配置Build Path
为对库的基本目录使用相同的“变量” ,指向不同机器上的不同位置,但仍将我的项目描述签入源代码管理,以便在添加新库时指定其相对于库位置基地,它是在两台机器上发现了什么?
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?
在“Java > 构建路径 > 类路径变量”或其他地方?
I have done a fair bit of "blind trial and error" already.. like stitching forms like "${env:VAR}" in there..
我已经做了相当多的“盲目试验和错误”......比如在那里拼接像“${env:VAR}”这样的表格......
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...
哦,我想我应该提一下,考虑到我的系统的环境变量是由 Bash 设置的,我不知道如何根据环境变量设置这些 Eclipse 变量,.profile
而且我怀疑 Eclipse 之前是否运行过 shell 来获取该变量...
/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 systemenvironment variable, full stop?!)
当然,我使用“配置构建路径 > 库 > 添加变量”,然后从那里扩展,但仍然......一个例子价值 1000 字......(可能是定义一个 Eclipse 变量,从那里到Extend
实际的 .包含在构建路径中的 jar 引用不能基于系统环境变量,句号?!)
PS: please don't ask me to just symlink things around, I am not a sysadmin on the shared machine..
PS:请不要让我只是符号链接周围的东西,我不是共享机器上的系统管理员..
采纳答案by Adam
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:
据我了解,扩展路径变量非常适合您的情况,因为您可以为每台机器定义不同的基本路径,并基于该路径在子路径上定义参考库。但是,如果您特别想使用环境变量,则可以尝试以这种方式将它们添加到构建路径中:
- Edit your launch configuration.
- Go to the Classpathtab.
- Click on User Entriesand click the Advancedbutton.
- To add a library based on a system environment variable, select Add
Variable String, and in the box type:
${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.
- 编辑您的启动配置。
- 转到类路径选项卡。
- 单击用户条目,然后单击高级按钮。
- 要添加基于系统环境变量的库,请选择Add Variable String,然后在框中键入:
${env_var:libs_base}/logging/slf4j.jar
。在这种情况下,libs_base
是您的环境变量,logging/slf4j.jar
是子目录中 jar 的路径。