1

I'm using eclipse with svn and when I add some .jar files to my Build Path eclipse add the jar with the full path from the root.

I know for sure that the file will always be in a folder called lib in the same directory as my project:

for example: ~/lib ~/proj

Can I add the file taking my project's directory as a reference? Something like ../lib?

Because, right now, when somebody makes an update the Build Path needs to be changed...

Thanks a lot

jlazevedo
  • 82
  • 2
  • 7

1 Answers1

1

under

Window > Preferences > java > Build Path > User Libraries 

you can define user libraries, witch you can add to your class path. just say new type in a name (for example MY_EXTERNAL_LIB_FOO) and hit ok. Then select it (simple click) and hit add JAR..., you can then brows your jars and add the ones you want (multi select is possible)

the entry in .classpath will look something like this

<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/MY_EXTERNAL_LIB_FOO"/>

this way you can abstract the location for the libs for your projects, they only need to know the name, Eclipse needs to know where the Libs for a name are located.

If you are versioning the libs too within you project then when editing the Build path hit add JARs... and not add External JARs... you will be prompted wi a list of all the project in the actual workspace, choose the onse you have in your project. the entries in .classpath will be relative to your project.

So if you have the following project layout

+ MyProject
    + src
    + lib
       some_3rd_party_lib.jar

then the entry in .classpath will look like

<classpathentry kind="lib" path="lib/some_3rd_party_lib.jar"/>
A4L
  • 17,353
  • 6
  • 49
  • 70
  • the main problem is that lib isn't "inside" MyProject is at the same level... so is an External JAR. – jlazevedo Mar 11 '13 at 21:09
  • You can but you should not, `.classpath` is changed when you use `configure classpath` from the UI. Ihave one question before answering your first question: do you commit the jars to svn in exactly the path you have mentioned, so when you do a fresh checkout you have exactly the same directory structure ? – A4L Mar 11 '13 at 21:18
  • Sorry, probably my mistake. I don't have lib/ in my repository. It's an external folder but by agreement all project members have the folder in the same directory as project svn checkout folder – jlazevedo Mar 11 '13 at 21:33
  • well, you can import the libs directory into your workspace as general project (unchek `Use default location` and browse to the location of the directory `libs`), once you have that project in your workspace your libs will no longer be external, so you can add to build path with `add JARs...`. You and your team members need to use the same project name for libs. you can also go with my first suggestion from my answer (`User Libraries`). Using both method will lead in relative paths/references in `.classpath` witch is good. Of course, all this assuming you commit the `.classpath` file to svn! – A4L Mar 11 '13 at 21:50
  • beside that i think libs should also be commited to svn so all members have the same version of them. Imaging you use a newer version with some new APIs and commit you code based on that, when other members update their working copies their project will be brocken. the same can happen to the daily builds. Versioned libs is a kind of agreement too ;-) – A4L Mar 11 '13 at 21:54