Java Build Path - Add External JARs' and Add Variable

南楼画角 提交于 2019-12-10 19:27:52

问题


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:


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.



来源:https://stackoverflow.com/questions/2729587/java-build-path-add-external-jars-and-add-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!