Eclipse 添加库与为 Java 项目添加变量
我试图找出 Eclipse 中的“添加变量”和“添加库”按钮之间的区别。那么到底什么时候应该使用添加库而不是添加变量呢?任何对最佳实践的解释都会很棒。
I am trying to figure out the difference between Add Variable and the Add Library buttons in Eclipse. So exactly when should add library be used instead of add variable? any explanation of best practices would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于变量的构建路径条目是通过相当于环境变量的 Eclipse 对单个 jar 的引用。您可以在工作区首选项中控制这些变量。
基于库的构建路径条目是一个更灵活的系统,其中您的构建路径引用动态解析的符号条目。每个条目可以解析为任意数量的 jar。库的类型有很多,并且可以通过插件添加新类型。例如,在基本的 Eclipse 安装中您将看到“JRE System Library”。该类添加了来自 rt.jar 等的标准 java 类。最常用的库是“用户库”。这允许您命名工作区中的 jar 集合,然后将构建路径上的这些 jar 作为一个单元引用。
A variable-based build path entry is a reference to a single jar via an Eclipse equivalent of an environment variable. You control these variables in workspace preferences.
A library-based build path entry is a more flexible system where your build path refers to a symbolic entry that is resolved dynamically. Each entry can resolve to any number of jars. There are many types of libraries and new types can be added by plugins. For instance, in a basic Eclipse install you will see "JRE System Library". That one adds standard java classes from rt.jar and others. The most commonly used library is the "User Library". This allows you to name collections of jars in the workspace and then refer to these jars on the build path as a unit.
当您不将依赖的 jar 放在与源代码相同的源代码控制下时,添加变量非常有用,并且当您在 eclipse 之外还有 ant 或 maven 构建系统时也很有用。
Add variable is useful when you don't keep your dependent jars under the same source control as your source code, and is also useful when you also have say an ant or maven build system outside eclipse.