Eclipse中源代码的相对路径 [英] Relative paths for source in Eclipse

查看:133
本文介绍了Eclipse中源代码的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,Eclipse和相对路径...

So, Eclipse and relative paths...

我想要实现的是与多个用户共享项目文件,其中源的确切位置对于每个用户是不同的。

What I want to achieve is to share the project files with several users, where the exact location of the source can be different for each user.

即,项目MyProject的src可以在 c:\version_control_foo\MyProject\src c:\version_control_bar\MyProject\src 甚至 X:\foobar\MyProject\src 同一个项目应该为所有人工作。

I.e, the src for project MyProject could be at c:\version_control_foo\MyProject\src or c:\version_control_bar\MyProject\src or even X:\foobar\MyProject\src and the same project should work for all.

我已经尝试过:
我在Eclipse中设置一个变量C_TMP,指向 c:\version_control_foo 的想法是用户#2将启动Eclipse与变量的不同设置。然后我使用该变量创建了一个链接的源文件夹。

Heres what I've tried: I set a variable C_TMP in Eclipse pointing to c:\version_control_foo with the idea that user #2 would start up Eclipse with a different setting for the variable. Then I created a linked source folder using the variable.

在我的 .project 文件中创建了此条目:

This created this entry in my .project file:

<linkedResources>
    <link>
        <name>C_TMP</name>
        <type>2</type>
        <locationURI>C_TMP</locationURI>
    </link>
</linkedResources>

<variableList>
    <variable>
        <name>C_TMP</name>
        <value>file:/C:/version_control_foo</value>
    </variable>
</variableList>

变量没有改变任何东西,这是有道理的,因为它似乎项目复制了的价值。

A change of the variable didn't change anything, which makes sense since it seems the project copied the value of it.

根据这个问题我想我可以通过让所有的src文件夹相对于工作区的位置来实现,但这并不是一个很好的解决方案。

Based on this question I guess I'll be able to do it by having all src folders relative from the workspace location, but that's not really a good solution.

我认为maven将能够通过生成Eclipse项目来处理这个问题(对吗?),但是我想用纯Eclipse来处理这个问题,没有特殊的魔术脚本。

I think maven will be able to handle this by generating Eclipse projects (right?) but I'd like to handle this with pure Eclipse and no special magic scripts.

编辑:这个工作就像我希望如果我用它来添加更多的库。为什么我的源文件夹不起作用?

This works just like I was hoping if I'm using it to add more libraries. Why won't it work with my source folders?

Edit2:根据评论进行一些说明。具有源文件夹和文件的整个项目都可用于版本控制。但这些文件的实际路径对于每个用户都是唯一的。从版本控制中检出不涉及任何类型的复制到本地可以被定义为相同的位置。

Some clarifications based on comments. The entire project with source folders and files are available in version control. But the actual path to those files are unique for each user. Checking out from version control doesnt involve any kind of copying to a local location that could be defined the same for all.

链接的源文件夹意味着我可以将其定义为与变量相对。然后可以为每个用户设置此变量。问题是,变量的值似乎被复制到.project文件中,而不是在Eclipse中设置的值。

A linked source folder means I can define it to be relative to a variable. This variable could then be set for each user. Problem is, the value of the variable seems to be copied to the .project file and not go by the value set in Eclipse.

推荐答案

好的,我想我找到了我需要的东西。在Eclipse中,我可以设置链接的资源,我可以在定义链接的源文件夹时使用。此变量可以更改,源文件夹将相应更改。如果我可以在启动时设置链接的资源,那么我就完成了。

Ok, I think I found what I needed. In Eclipse I can set a linked resource that I can use when defining linked source folders. This variable can change and the source folders will then change accordingly. If I can set the linked resource at startup somehow, then I'm all done.

此问题

转到窗口>首选项然后到常规>工作区>链接资源并在此定义您的文件夹。然后可以在项目中使用定义的变量。

Go to Window > Preferences then to General > Workspace > Linked Resources and define your folder here. Then you can use defined variable in project.

这篇关于Eclipse中源代码的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆