Java 构建路径 - 添加外部 JAR并添加变量

发布于 2024-08-30 05:40:33 字数 63 浏览 3 评论 0原文

Java 构建路径 - 添加外部 JAR 按钮和添加变量按钮功能之间有什么区别, 为什么需要它。请详细解释一下。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-09-06 05:40:33

两者都可以用来实现相同的目标:将 JAR 添加到构建路径中。

假设您有一个项目 P1,想要使用供应商 S1 安装的 JAR,该 JAR 恰好位于 C:\S1\aproject\jars\Useful.jar

客户端添加外部 JAR,导航、选择,然后就完成了。

但是,请考虑这些情况。

1)。假设您有多个项目都想要使用同一个 JAR?您最终会对项目 P1-PN 重复此操作。变得迟钝。更糟糕的是,假设您安装了 S1 堆栈的新版本,现在您需要更新所有这些项目的构建路径以进行引用,

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

更糟糕的是,如果您错过了一个,那么您正在运行两个版本的 JAR,这可能会非常糟糕!

2)。您与一位同事共享一个项目,而该同事恰好在不同位置安装了 S1 产品。他们现在需要修改项目以指向

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

“如果您使用的是 SCM,那么您可能会踩到对方的脚趾”。

因此:

相反,添加变量允许您定义一个工作区变量(即特定于您的环境),然后可以使用该变量来引用该 JAR

 $(S1_JARS)\\Useful.jar

现在您可以在一个地方更新到新版本的 S1,每个开发者都可以为S1_JAR设置自己的值。

我建议在重要的开发场景中使用变量。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文