java eclipse build path options question
Asked Answered
R

3

5

I have a question on Eclipse (I am using Helios).
When a project depends on various libraries, we add them to the classpath via the Build Path Dialog.
In the same dialog though, there is a tab for Projects (Required Projects on the build path).
It is not clear to me, when someone would add such a reference from one project to another.
I mean, if projectA needs functionality from projectB, then we can make a jar out of projectB and use it in projectA.
But when, would we add then, a reference from projectA to projectB, in order to need projectB in the build path of projectA?
Could someone please give an example?
Thank you!

Rondo answered 26/1, 2011 at 20:43 Comment(0)
L
4

Well, there are two reasons for depending on a project.

  1. You can "click through" to the source code of the other project when its code is invoked.
  2. If you're building and running the application in Eclipse for dev purposes, changes in the code will instantly be picked up.

Update: I thought of a third one, possibly even better than the first two. There is an "Order and Export" tab in the same screen, where you can select which elements of a project's classpath are exported. And what "exported" means here is exactly that if project B is configured to have project A as a dependency, then it will automatically add all the exported libraries from project A to its own classpath. So if project A has a lot of thrid party libraries, you don't have to manually add them to project B's classpath.

Lemonade answered 26/1, 2011 at 20:47 Comment(0)
D
3

"Required Projects" allow you to state dependencies between projects without the need to build a jar each time you make a change to the project you depend upon.

Delphinedelphinia answered 26/1, 2011 at 20:46 Comment(3)
Yes, it is simply a convenience. A very nice one at that!Cervical
So the idea is that you import for example class X from package a.b.c and then you point a reference to ProjectB which defines it?Rondo
Yes, that'is it. It adds the contents of the specified project into your classpath.Delphinedelphinia
S
1

One (for me nice, for others; perhaps, blasphemous) use of the "Project Dependancy" is when you have a seperate project for unit tests. Make the unit test project depend on the to-be-tested project. Of course, this is only nice if you are not a maven or hudson or blah, blah, blah user (like me). Not that blah, blah, blah are bad things.

Schober answered 26/1, 2011 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.