eclipse 有没有办法设置相对于 .project 文件的链接资源?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4000039/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:42:27  来源:igfitidea点击:

Is there a way to setup Linked Resources relative to the .project file?

eclipseversion-controlprojectrelative-path

提问by JohnWithoutArms

We have a Flash Builder (which is based on Eclipse) project that pulls source from different locations, included in the source control in which the project is. As per our organization requirements, the source code is present in directories not directly under the project directory. Initially we had the problem that all paths to the linked resources were absolute and did not work on other machines with different paths.

我们有一个 Flash Builder(它基于 Eclipse)项目,它从不同位置提取源代码,包含在项目所在的源代码控制中。根据我们的组织要求,源代码存在于不直接位于项目目录下的目录中。最初我们遇到的问题是链接资源的所有路径都是绝对路径,并且在其他具有不同路径的机器上不起作用。

Right now, the solution we have for this is to set up a Linked Resource Path Variable that points to the root of the working folder. All other locations are based on that, so we can include source from folders like

现在,我们对此的解决方案是设置一个指向工作文件夹根目录的链接资源路径变量。所有其他位置都基于此,因此我们可以包含来自文件夹的源,例如

${WORKING_BASE}/library1
${WORKING_BASE}/library2

The problem with this solution is that everyone that pulls the project has to set the WORKING_BASE variable correctly before opening the project for it to work. My question is, is there a way to make the Linked Resources relative to the location of the .project file? That would be ideal.

此解决方案的问题在于,每个拉动项目的人都必须在打开项目以使其工作之前正确设置 WORKING_BASE 变量。我的问题是,有没有办法让链接资源相对于 .project 文件的位置?那将是理想的。

回答by Matthias

It is possible since Eclipse 3.6 (Helios)

从 Eclipse 3.6 (Helios) 开始就有可能

Open the project properties and goto Resources > Linked Resources > Path Variables.

打开项目属性并转到资源 > 链接资源 > 路径变量。

There you can create a new variable relative to an existing one. For instance:
Name: MY_SOURCE_FOLDER
Location: ${PROJECT_LOC}\..\src

在那里您可以创建一个相对于现有变量的新变量。例如:
名称:MY_SOURCE_FOLDER
位置:${PROJECT_LOC}\..\src

This will add a new Path variable to your .project file with a value like:

这将向您的 .project 文件添加一个新的 Path 变量,其值如下:

$%7BPARENT-1-PROJECT_LOC%7D/src

meaning ${PARENT-1-PROJECT_LOC}/src, where the 1means the parent directory 1 times above PROJECT_LOC.

意思是${PARENT-1-PROJECT_LOC}/src,这里的1意思是PROJECT_LOC上面的父目录1倍。

回答by Sébastien

With eclipse 3.7, giving this path :

使用 Eclipse 3.7,给出这条路径:

C:\projects\workspace\project1
C:\projects\workspace\project2

Within project1 you can do :

在 project1 中,您可以执行以下操作:

PROJECT_LOC => C:\projects\workspace\project1
PARENT-1-PROJECT_LOC => C:\projects\workspace
PARENT-2-PROJECT_LOC => C:\projects\
PARENT-1-PROJECT_LOC\project2 => C:\projects\workspace\project2