开发者

How to use relative paths for projects added to an Eclipse workspace?

I am working on some Eclipse projects that are stored on a USB key. I have added them to a workspace whose root folder is also on the USB key, but the projects are not located directly into this directory. As a result their absolute paths are written in the .projects folder of the workspace.

This raises problems when I use the key on several开发者_C百科 computers, because the drive letter assigned to the USB key is not always the same (and I do not want to assign a specific letter to it on all computers). Eclipse cannot open my projects when the drive letter differs from that of the USB key at the time I added the project to the workspace.

Is there a solution to this problem ? Specifically, is there a way to make Eclipse add projects to a workspace by using their relative path from the workspace folder ?


Its really not that hard. You just have to assign a new variable that points to WORKSPACE/..;. For example, you can use the Forge Minecraft modder pack - it has a workspace that is immediately ready no matter what machine downloads it, where you place it or even if you move it.

Download this: http://files.minecraftforge.net/minecraftforge/minecraftforge-src-1.6.2-9.10.0.789.zip

And then unzip it and run install.bat/cmd. Then check the contents of forge/mcp/eclipse/Minecraft/{.project,.workspace} to see some examples.

I've got my workspace working on github like this.


In my experience it will break at some time if you try to "hack" the metadata of eclipse.

Consider the substcommand in windows (As you mention drive letter I assume windows)

create a bat file containing

subst N: .

Running this will mount the current dir as N: So You can place this on the usb drive, and run that prior to running eclipse, then You will always find the same content on drive N:

To remove the mount do

subst /D N:

You might consider making a bat file that mount N:, start eclipse and after eclipse exit unmount N: something like

startMyProject.bat:

subst N: .
N:/eclipse <yadayada options>
subst /D N:


The short answer is that you cannot do it without hacking your workspace metadata (under [workspace.dir]/.metadata). Eclipse workspaces aren't designed to be portable and even though you are not physically moving your workspace, you are in effect moving it by changing drive letters.

I'd recommend trying to find a way to have your projects under workspace.dir. Not guaranteed that you will not have problems that way, but may improve your odds. Depending on what features of Eclipse you use, you may very well end up with other types of absolute paths in your workspace metadata.


This question is kinda old, but there's an entirely different approach: You can create a Junction from the Folder where Eclipse expects the Project, for example E:\foo\workspace\myproject and link it to where the project lays, for example E:\bar\myproject.

A Junction essentially means that you can access the same folder through 2 different paths, thus you don't need to worry with the weird relative path limitations of Eclipse. To create it easily and fast, I recommend you to get Link Shell Extension


I haven't tried this myself, but this might work. Try:
Add your source folder as linked resource & remove previous definition: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.user/tasks/tasks-45.htm

Close eclipse and find your project folder in your workspace (ex: C:\Documents and Settings\username\workspace\yourproject\) Replace absolute paths in files .project & .classpath with relative paths.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜