How can I add build path items to Eclipse 3.5 using relative paths?
Asked Answered
R

9

23

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 indicate that I have to manually edit the .classpath file. Am I just missing something?

Edit 2015: Updated link as it had went away. To preserve the "new and noteworthy" indefinitely, here's a screenshot of the mentioned section.

enter image description here

Remindful answered 15/9, 2009 at 13:3 Comment(1)
+1 it looks like you can only do it by hacking the classpathBoatright
R
3

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.

Remindful answered 16/9, 2009 at 13:22 Comment(2)
just wondering: how did you manually do that? Whenever I put a file pattern like ../name.jar into the classpath, Eclipse craps out (that's Galileo)Vast
@Matthias: I see the same with Helios.Adventurism
C
11

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

Collis answered 15/9, 2009 at 23:26 Comment(2)
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 environmentRemindful
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!Collis
C
11

I'm uing Helios (i.e. 3.6.x) and this is what I do to reference a lib (jar) outside of my project in a relative manner.

1) Right click project in project explorer -> Import -> Import. 2) Select File System (Next) Use the browse button to navigate to the folder (yes, it looks like a hard-path). Select the .jar(s) to include.

I usually append "\lib" to the project name in the "Into Folder:" option.

Click "Advanced" and select the "Create Links in workspace" and I use the default options (both checked, and relative to PROJECT_LOC). 3) Click Finish

Next, open up the project properties and go to Java Build Path Libraries tab and select "Add Jars..." and go to the \lib folder (from Step 2) and select the lib(s) that you need. On the Libraries tab now has "ProjectName/Lib" for the path of the lib(s).

The project explorer will display a lib folder with your libs with a special icon. If you look in your hard drive for the lib folder, there is nothing there. So it is referring to the libs in the external path, but including them as a "project" lib.

Right click on the jar file in the project explorer and do properties. You should see the relative path goodness.

Conviction answered 11/11, 2010 at 20:54 Comment(2)
Perfect! Using this method, a virtual folder is created to contain you jar files. The jar files themselves are not copied but kept on their original location and referenced using a relative path (e.g. <project-location>/../../mylittle.jar).Eohippus
Did you have to setup PROJECT_LOC or was it predefined?Blindage
D
8

Simple. without all dialogs and menus.

In your .project file add the path to the real file, like this. Mine is on ../libs/GoogleAdMobAdsSdkAndroid-4.1.1/GoogleAdMobAdsSdk-4.1.1.jar
so i changed to PARENT-1-PROJECT_LOC/libs/...

<linkedResources>
    <link>
        <name>libs/GoogleAdMobAdsSdk-4.1.1.jar</name>
        <type>1</type>
        <locationURI>PARENT-1-PROJECT_LOC/libs/GoogleAdMobAdsSdkAndroid-4.1.1/GoogleAdMobAdsSdk-4.1.1.jar</locationURI>
    </link>
</linkedResources>

and in .classpath i use

<classpathentry kind="lib" path="libs/GoogleAdMobAdsSdk-4.1.1.jar"/>

as the link to the lib

Eclipse links the resource to project and uses it without copping the file Just like Mike Jones answer above but without any dialogs

Best for multiple apps

Devonadevondra answered 26/3, 2012 at 17:34 Comment(0)
P
5

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?

Phiphenomenon answered 15/9, 2009 at 13:3 Comment(0)
L
3

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.. ;-)

Loftus answered 15/9, 2009 at 13:13 Comment(3)
That is for adding variables rather than direct relative paths. Not what was asked for at allBoatright
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..Loftus
@Remindful This is exactly what you need. Some of these variables will give you the project directory which you can use and reference your jar relative to it.Spadiceous
R
3

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.

Remindful answered 16/9, 2009 at 13:22 Comment(2)
just wondering: how did you manually do that? Whenever I put a file pattern like ../name.jar into the classpath, Eclipse craps out (that's Galileo)Vast
@Matthias: I see the same with Helios.Adventurism
D
0

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.

Duce answered 15/9, 2009 at 21:27 Comment(0)
W
0

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

Weigel answered 9/10, 2009 at 5:59 Comment(0)
D
0

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.

Delusive answered 15/10, 2009 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.