tags:

views:

510

answers:

7

Eclipse 3.5 added support for relative buildpath/classpath items, yet I cannot seem to find a graphical way to add relatively pathed items. The example in new and noteworthy (search the page for 'relative', about 40% of the way down) seems to indication I have to manually edit the .classpath file. Am I just missing something?

+1  A: 

I think you can do this graphically instead of editing .classpath. Depending on Eclipse version it's something like:

Right-click project --> Properties --> Build Path --> Libraries (tab) --> Add Variable

Works in my current Eclipse with a Java project.. ;-)

NickDK
That is for adding variables rather than direct relative paths. Not what was asked for at all
Rich Seller
Guess I'm missing the point of your question. I thought you wanted to change the .classpath to add something like: <classpathentry kind="var" path="MYCLASSPATHVAR/someLibrary.jar"/>But using the graphic interface. My bad..
NickDK
nope. Wanted to add an entry like "../../lib/junit.jar"
basszero
A: 

As far as I know you currently can only achieve this by editing the .classpath file. For this to be possible through pure 'button pushing' the browse dialogs popping up after selecting 'Add External JARs...' and 'Add External Class Folder...' would need something like a check-box to specify if you want to add the relative or the absolute path. Maybe that is not hard to add, but I haven't seen it yet.

Simon Groenewolt
+2  A: 

The actual way to do this is to import the library into your workspace so,

Right Click in Package Explorer -> Import -> File System -> Browse (to the directory containing your jars) -> check the boxes next to the jars you want -> Browse to the workspace folder you want to import to (probably your lib folder) -> Finish

Keep in mind this will copy the files into the lib folder so I've found that it helps keep things clean if you don't already have them in there. They will now show up in the package explorer under "lib." To add them to the classpath,

Right click on the project -> Build Path -> configure build path... -> Add JARs -> navigate to the given project's lib folder and select the appropriate JARs -> click ok -> click finish

This adds them to the CP with relative locations.

If you need more help let me know

Chris Thompson
Not quite. I don't want to import the jars into the project, I want to refer to my lib directories (which are external and several parent dirs away) via relative paths so that anyone who checks out my projects won't have to set variables or environment
basszero
The eclipse relative build paths are project relative. As far as I know, the only way to get eclipse to actually refer to things in that manner is to have them inside the project in the project manager. You might be able to use operators like .. to refer to other directories, but I know of no way to graphically accomplish that. Sorry!
Chris Thompson
A: 

After evaluating all responses and tinkering with Eclipse I can see no way to do this without manually editing the .classpath file.

Marking this answer as accepted to indicate that there is no way to do this in Eclipse 3.5. Keep fingers crossed for Eclipse 3.6 or Eclipse 4.

basszero
A: 

No. As of yet, it is not possible. But you will be seeing it soon. Keep checking the intergration builds.

Suraj Chandran
A: 

This does not work!

Editing the .classpath to include relative paths as per the New and Noteworthy example (path="../../lib/myjar.jar") isn't difficult, however it does not appear to work as described!

It seems to resolve relative to the Workspace and not the specific Project as specified, which is not much use. Has anyone else found the same problem or a solution to this?

Gair
A: 

I've done this by adding the libraries to my project. So, create a folder under your project called "jars" and put all dependent jars in there.

When you configure the build path afterward, everything will be relative.

vinnybad