Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

path

eclipse

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 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 ?

like image 220
Dunaril Avatar asked Mar 03 '11 09:03

Dunaril


2 Answers

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.

like image 74
hanetzer Avatar answered Sep 25 '22 23:09

hanetzer


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:
like image 33
Otzen Avatar answered Sep 24 '22 23:09

Otzen