在 Eclipse 中将用户库定义为项目而不是工作区的一部分
我看到在 Eclipse 中我可以定义用户库 - 以使设置类路径更容易(也可能出于其他原因)。
问题是,这些库仅在工作区中可用,如果我希望使用同一项目的其他人使用它们 - 我需要导出我的用户库,而他们需要导入它。
项目级别有类似的功能吗?我基本上需要有一个“类路径组” - 可以做到吗?
如果没有,是否有一种自动方式可以在导入项目时自动将用户库导入到工作区?
我正在使用 Eclipse 3.6。
I saw that in Eclipse
I can define User Libraries - to make setting the classpath easier (and probably for other reasons as well).
The problem is, that these libraries are only available in the workspace, and if I want other people using the same project to use them - I need to export my user library and they need to import it.
Is there any functionality like this on the project level? I basically need to have a 'classpath group' - can it be done?
If not, is there an automatic way to auto import the user library to the workspace when importing the project?
I'm using Eclipse 3.6
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JDT 有两个概念:用户库和类路径变量。在类路径变量中,您可以将 jar 添加到项目中。其他团队成员必须填写工作区中的变量,以便他们的类路径完整。当外部 jar 可能位于每个团队成员本地文件系统的不同位置时,这非常有用。
USER_LIBRARY 是一个用于一次性添加本地 jar 逻辑组的容器。例如,JRE_LIB 容器代表许多本地 jar。但正如您所看到的,它指向一组旨在在多个项目中使用的本地 jar(因为 JRE 已添加到多个项目中)。
除了导出/导入(您已经在做)之外,我不相信您可以将 CLASS_LIBRARIES 检查到项目的 SCM 中。如果有,首选项页面顶部将有一个“配置项目特定设置”链接。
最好的选择是简单地将 jar 添加到项目中,这样它们就会包含在 SCM 中。如果它们可以位于不同的位置,具体取决于团队的其他成员,则使用类路径变量,以便可以在每个工作区中进行设置。就团队成员检查项目并准备开始而言,这是最少的麻烦。
JDT has the 2 concepts, user libraries and classpath variables. In the classpath variable, you can add jars to your project. Other team members have to fill in the variables in their workspace so their classpath is complete. This is useful when external jars might be in different locations on each team members local file system.
The USER_LIBRARY is a container for adding a logical group of local jars all at once. For example, the JRE_LIB container represents a number of local jars. But as you've seen, it points to a local set of jars meant to be used in multiple projects (as the JRE is added to multiple projects).
Aside from export/import (which you're already doing), I don't believe you can check CLASS_LIBRARIES into a project's SCM. If there was, the preference page would have a "Configure Project specific settings" link at the top.
Your best bet is to simply add the jars to the project, so they'll be included in the SCM. If they can be in different locations depending on the rest of your team, then use a classpath variable so it can be set in each workspace. That's the least amount of hassle as far as team members checking out the project and being ready to go.
IMO 的最佳方法是使用 m2eclipse - eclipse 的 Maven 插件。在 Maven 中,所有依赖项都在 pom.xml 中定义,并根据需要自动下载。这意味着您与团队共享的唯一内容是 pom.xml - 您的项目定义。
与标准 Eclipse 方法相比,使用 m2eclipse 具有更多优势。更多信息请访问 http://www.sonatype.com/books/m2eclipse-book/参考/
The best way IMO is to use m2eclipse - Maven plugin for eclipse. In Maven all the dependencies are defined in pom.xml and downloaded automatically as needed. This means that the only thing you share with your team is pom.xml - your project definition.
There is a lot more advantages when using m2eclipse vs standard eclipse approch. More information is at http://www.sonatype.com/books/m2eclipse-book/reference/
我使用用户库的方式是针对像 Ant 这样的东西。为 ANT_HOME/lib 中的所有 jar 定义一个用户库“ant”。如果将其包含在您的 Eclipse .classpath 中,然后与其他用户共享,他们将获得构建问题报告,直到他们自己创建该“ant”用户库。它很有用,但您需要分享有关如何创建库的知识。如果您将它用于像上面这样的简单情况,那么向库添加正确的 jar 的说明非常简单。
我使用的另一种方法是构建指向在 Eclipse 中定义为变量的文件夹(或多个文件夹)的类路径。请参阅
文件 ->新文件夹->高级->链接到文件系统中的文件夹->变量。这使您可以(再次在工作区级别)设置对一个或多个文件夹的变量引用。然后,您可以参考该文件夹构建 Eclipse 类路径。
因此,在您的开发环境中,每个人都需要有一个名为“thirdparty”的目录,其中包含所有外部 jar 依赖项(可能在该目录内的层次结构中:thirdparty/apache;thirdparty/sun;...)。您将“第三方”定义为指向当前系统上该目录所在位置的变量,然后使用该变量在项目中创建一个文件夹。然后,您可以使用该文件夹的路径来设置(和共享)类路径。
它与用户库类似,并且具有类似的限制。限制是您与之共享项目的其他用户必须像您一样创建变量文件夹。但它更灵活,因为他们不必像使用库那样显式添加 jar;相反,Eclipse 中的类路径根据每个项目的需要指向该文件夹。
请注意,虽然文件夹变量是在工作区级别定义的,但它可以在多个项目中重用,每个项目都会使用不同的引用构建其类路径(.classpath 文件)到文件夹中。
这可能比用语言描述更容易展示,但我希望它是有道理的。
The way I have used user libraries is for something like Ant. Define a user library "ant" for all the jars in ANT_HOME/lib. If including this in your Eclipse .classpath and then sharing with other users, they will get a build problem report until they create that "ant" user library themselves. It's useful, but you need to share knowledge on how to create the library. If you're using it for simple cases like above, then instructions for adding the right jars to the library are straightforward.
Another approach I've used is to build classpaths pointing into a folder (or folders) defined as a variable in Eclipse. See
File -> New Folder -> Advanced -> Link to folder in the file system -> Variables
. This lets you setup (again at workspace level) variable references to one or more folders. You can then build your Eclipse classpath/s with reference to the folder/s.So say in your development environment, everyone needs to have a directory called "thirdparty" containing all the external jars dependencies (probably in hierarchy within that dir: thirdparty/apache; thirdparty/sun; ...). You define "thirdparty" as a variable pointing to wherever that dir is on your current system, you create a folder in your project/s using the variable. You can then setup (and share) classpath using paths into that folder.
It's similar to User Library and with similar limitations. The limitation is that the other users you share your project with must create variable folder/s as you have. But it's more flexible in that they don't have to add the jars explicitly as they do with a library; rather, your classpath/s in Eclipse point into the folder, as required for each project.
Note that although the folder variable is defined at workspace level, it can be reused in multiple projects, each of which builds their classpaths (.classpath files) with different references into the folder).
This is maybe something easier to show than to describe with words, but I hope it makes sense.