Relative paths for source in Eclipse

牧云@^-^@ 提交于 2019-12-10 09:27:12

问题


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.

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.

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.

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.

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.

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.

Edit: 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.

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.


回答1:


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.

From this question

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



来源:https://stackoverflow.com/questions/8327707/relative-paths-for-source-in-eclipse

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