28

We have a Flash Builder (which is based on Eclipse) project that pulls source from different locations, included in the source control in which the project is. As per our organization requirements, the source code is present in directories not directly under the project directory. Initially we had the problem that all paths to the linked resources were absolute and did not work on other machines with different paths.

Right now, the solution we have for this is to set up a Linked Resource Path Variable that points to the root of the working folder. All other locations are based on that, so we can include source from folders like

${WORKING_BASE}/library1
${WORKING_BASE}/library2

The problem with this solution is that everyone that pulls the project has to set the WORKING_BASE variable correctly before opening the project for it to work. My question is, is there a way to make the Linked Resources relative to the location of the .project file? That would be ideal.

Machavity
  • 30,841
  • 27
  • 92
  • 100
JohnWithoutArms
  • 541
  • 2
  • 6
  • 5

3 Answers3

45

It is possible since Eclipse 3.6 (Helios)

Open the project properties and goto Resources > Linked Resources > Path Variables.

There you can create a new variable relative to an existing one. For instance:
Name: MY_SOURCE_FOLDER
Location: ${PROJECT_LOC}\..\src

This will add a new Path variable to your .project file with a value like:

$%7BPARENT-1-PROJECT_LOC%7D/src

meaning ${PARENT-1-PROJECT_LOC}/src, where the 1 means the parent directory 1 times above PROJECT_LOC.

xav
  • 5,452
  • 7
  • 48
  • 57
Matthias
  • 2,418
  • 1
  • 16
  • 7
  • Thanks a ton for this answer. This works... They should add this to Eclipse Help Page – Vincent Vettukal Jun 13 '12 at 23:05
  • 1
    I was getting mad about this - thanks for this nice explanation. Of course Sébastien spoke about the same thing, but you described it better :) – Thomas Keller Aug 15 '12 at 10:14
  • @tommyd , no Sebastien didn't talk about adding a new variable, you can just use to those (quite cryptic IMHO) references directly in links. Just what I wanted – inger Jul 24 '13 at 20:08
  • Thanks a ton bro. This answer is still valid for Luna. Saved me a ton of headache. – Sushant Gupta Feb 05 '16 at 04:35
31

With eclipse 3.7, giving this path :

C:\projects\workspace\project1
C:\projects\workspace\project2

Within project1 you can do :

PROJECT_LOC => C:\projects\workspace\project1
PARENT-1-PROJECT_LOC => C:\projects\workspace
PARENT-2-PROJECT_LOC => C:\projects\
PARENT-1-PROJECT_LOC\project2 => C:\projects\workspace\project2
Sébastien
  • 411
  • 4
  • 3
0

Use ${PROJECT_LOC} instead of ${WORKING_BASE}

Like:

${PROJECT_LOC}/library1

${PROJECT_LOC}/library2

Since project location is the base of the current project you can add relative path followed by it.

Adeel Ilyas
  • 176
  • 1
  • 8