views:

161

answers:

1

What is the difference between Java Build Path - Add External JARs Button and Add Variable Button Functionality, Why its required. Please explain in detail.

+1  A: 

Both can be used to achieve the same thing: add a JAR to your build path.

Suppose you have a project P1 that wants to use a JAR installed by supplier S1, which happens to be located at C:\S1\aproject\jars\Useful.jar

Client Add External JARs, navigate, select, and we're done.

But, consider these cases.

1). Suppose you have several projects that all want to use that same JAR? You end up repeating that for projects P1-PN. Gets dull. What's worse, suppose you install a new version of S1's stack, now you need to update all those project's build paths to reference

C:\S1\aproject-**v2**\jars\Useful.jar

And what's worse, if you miss one then you are running two versions of the JAR that may be really bad!

2). You share a project with a colleage who happens to have S1 product installed in a different location. They now need to amend the project to point to

 E:\MyFavouriteThings\S1\aproject\jars\Useful.jar

And if you are using an SCM you may tread on each others toes.

So:

Instead Add Variable allows you to define a Workspace variable (ie. specific to your environment) which can then be used to reference that JAR

 $(S1_JARS)\\Useful.jar

Now you a single place to update to a new version of S1, and each developer can set his own value for S1_JARs.

I would recommend using Variables for non-trivial development scenarios.

djna
Thank u verymuch djna.
Lakshman
Feel free to accept/upvote ;-)
djna