Eclipse Workspace/Project Setup Using Symlinks

6.1k views Asked by At

I have the following simplified setup:

~/Development/Repositories/ProjectA-trunk
~/Development/Repositories/ProjectA-branch
~/Development/workspace
~/Development/workspace/ProjectA

ProjectA is a symlink to ../Repositories/ProjectA-trunk. In an ideal world I'd be able to switch the link to point at ../Repositories/ProjectA-branch and then go refresh the project in Eclipse and be working on the branch.

In this unfortunate real world Eclipse, even though it says otherwise when importing the existing project initially, resolves the symlink and keeps the absolute path to the project in Properties>Resource>Location for "ProjectA", which is in this case ~/Development/Repositories/ProjectA-trunk. Therefore switching the symlink has no effect because Eclipse now thinks ProjectA lives at ~/Development/Repositories/ProjectA-trunk and not ~/Development/Repositories/ProjectA.

Does anybody have a solution or workaround or suggestion on how to set up your workspace to make working with branches like this work?

3

There are 3 answers

0
Yike Lu On

You can accomplish the same thing by creating your repository on an already existing workspace. Eclipse uses the .metadata folder in the workspace to determine what projects exist. Then have your branches in the same directory (using git for example). Anytime you want to switch branches you git checkout my_branch and then refresh in Eclipse.

In other words, don't use link, use git to manage the branches in the same directory.

Edit: full procedure goes something like this. Clone the repo outside of Eclipse (because the import nags you if it's in your workspace). Import into your workspace. Delete the folder inside your workspace and clone the repo into your workspace.

1
Max Nanasy On

To import the project initially (assuming ~/Development/workspace/ProjectA does not currently exist):

  1. mv ~/Development/Repositories/ProjectA-trunk ~/Development/workspace/ProjectA
  2. Import ~/Development/workspace/ProjectA into Eclipse
  3. mv ~/Development/workspace/ProjectA ~/Development/Repositories/ProjectA-trunk
  4. ln -s ~/Development/Repositories/ProjectA-trunk ~/Development/workspace/ProjectA
  5. Refresh Eclipse

Whenever you want to change the branch:

  1. ln -Tfs $BRANCH ~/Development/workspace/ProjectA
  2. Refresh Eclipse
0
Robert On

The symlink setup works for me with Mac OS and Eclipse (Indigo and Juno).

robert@pferdeapfel:~> ls -l ~/Documents/workspace/
total 8.0K
lrwxr-xr-x 1 robert staff   33 Dec 27 14:05 TheProject -> /Users/robert/prj/foo/Java

where foo is a symlink to whatever working copy I want to use.

robert@pferdeapfel:~> ls -ld ~/prj/foo
lrwxr-xr-x 1 robert staff 5 Dec 27 13:47 /Users/robert/prj/foo -> trunk

When switching, I rm ~/prj/foo and ln -s another working copy to foo. Refresh in Eclipse and it picks up the changes.

The trick here was that my project is only partly in Java, i.e., I have the working copy main folder (foo) and below that Java, Perl, Postgres, and so on. When I link to the main folder (i.e., ~/Documents/workspace/TheProject -> ~/prj/foo), Eclipse resolves the symlinks on importing and stores the resulting path in the project properties. Only when I have the symlink to the Java folder in the project (~/Documents/workspace/TheProject -> ~/prj/foo/Java, Eclipse preserves the symlinks.

The whole symlink stuff is useful when you have different working copies of the same branch / trunk and need to switch between them. Eclipse cannot handle the same project name twice. I don't want to lose my working copy changes. Hence the symlink.