Eclipse 项目的 JAR 文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1194119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAR file folder for eclipse projects
提问by Daff
I'm trying to create a centralized folder (in some kind of a "meta project" in my eclipse workspace) for commonly used JAR files for referenced projects in this workspace. It should work similar to the WEB-INF/lib folder for web projects but also apply to non web projects, and automatically scan and add all jar files in this folder.
我正在尝试为此工作区中引用项目的常用 JAR 文件创建一个集中文件夹(在我的 eclipse 工作区中的某种“元项目”中)。它应该类似于 web 项目的 WEB-INF/lib 文件夹,但也适用于非 web 项目,并自动扫描并添加此文件夹中的所有 jar 文件。
I tried to create a user library with these jar files and reference them in the project but I still have to add every new jar manually to the user library (and don't know if it is referenced relative of absoulute) and Tomcat (WTP) doesn't seem to take these files (Run As -> Run on Server) into its classpath (and I don't want to duplicate the jars and put them into WEB-INF/lib). Any ideas?
我试图用这些 jar 文件创建一个用户库并在项目中引用它们,但我仍然必须手动将每个新 jar 添加到用户库(并且不知道它是否被引用为绝对的相对)和 Tomcat (WTP)似乎没有将这些文件(运行方式 -> 在服务器上运行)放入其类路径(我不想复制 jars 并将它们放入 WEB-INF/lib)。有任何想法吗?
采纳答案by fg.
+1 for Ivy.
常春藤+1。
If you'd rather do it in a separated project in Eclipse:
如果您更愿意在 Eclipse 中的单独项目中执行此操作:
You added the 'common project' as on dependency for other projects (Java Build Path->Projects, then Add). But, have you exported the jars of the 'common project'? (In the common project: Java Build Path->Order and Export, then check all jars).
您添加了“公共项目”作为其他项目的依赖项(Java 构建路径-> 项目,然后添加)。但是,你有没有导出“共同项目”的罐子?(常见项目中:Java Build Path->Order and Export,然后勾选所有jar)。
回答by matt b
I would recommend against this, it becomes a pain in the butt when you have lots of projects with overlapping dependencies.
我建议不要这样做,当您有很多具有重叠依赖项的项目时,这会变得很痛苦。
What if Project X uses commons-logging-1.0 but someone creates Project Z which really needs commons-logging-1.1 instead? Do you want your central folder to have copies of the same JAR for each possible version number?
如果 Project X 使用 commons-logging-1.0,但有人创建了真正需要 commons-logging-1.1 的 Project Z,该怎么办?您是否希望中央文件夹为每个可能的版本号拥有相同 JAR 的副本?
Use a build tool like Maven or Ivy which will download and handle dependent JARs for you. The maven-eclipse plugin does a pretty good job of generating .project
/.classpath
files for Eclipse which will automatically put all dependent JARs on the build path, and m2eclipse is also good at handling dependencies from within Eclipse.
使用 Maven 或 Ivy 之类的构建工具,它们会为您下载和处理依赖的 JAR。maven-eclipse 插件在为 Eclipse生成.project
/.classpath
文件方面做得非常好,它会自动将所有依赖的 JAR 放在构建路径上,并且 m2eclipse 也擅长处理 Eclipse 中的依赖项。
回答by Stephen C
I think you should take a serious look at Maven. You simply declare what 'artifacts' each of your projects depends on, and Maven will take care of fetching the JARs from a repository, adding them to the build classpath, and including them in your WAR files. And if you want to a batch build, you don't need to create an Ant "build.xml" file: just run "mvn" from the command file.
我认为你应该认真看看 Maven。您只需声明每个项目所依赖的“工件”,Maven 将负责从存储库中获取 JAR,将它们添加到构建类路径,并将它们包含在您的 WAR 文件中。如果您想要批量构建,则不需要创建 Ant“build.xml”文件:只需从命令文件中运行“mvn”即可。
回答by Thorbj?rn Ravn Andersen
I would consider managing these things with the Ivy extension to Ant, which has the benefit of being maven compatible should you ever want to go that way.
我会考虑使用 Ant 的 Ivy 扩展来管理这些东西,如果您想这样做,它具有与 Maven 兼容的好处。
Just throwing everything in a big pile will give you problems eventually, as you will run into version problems when you suddenly have two projects where one uses the version available when THAT was created,a nd the other one the bugfixed version, and those are not 100% compatible.
把所有东西都堆成一大堆最终会给你带来问题,因为当你突然有两个项目时你会遇到版本问题,其中一个使用创建时可用的版本,另一个使用错误修正版本,而那些不是100% 兼容。
回答by Mauli
My colleague implemented a classpath container which recursivly looks for jars in a given directory within the workspace, have a look at http://openscada.org/news/dx/31.05.2010154336JREJ4U.htm
我的同事实现了一个类路径容器,它递归地在工作区中的给定目录中查找 jar,请查看http://openscada.org/news/dx/31.05.2010154336JREJ4U.htm
The update site can be found at http://repo.openscada.org/p2/bob/R
更新站点可以在http://repo.openscada.org/p2/bob/R找到
The plugin is licensed unter LGPL V3 and you can find the source code under http://pubsvn.inavare.net/openscada/modules/bob/trunk/
该插件在 LGPL V3 下获得许可,您可以在http://pubsvn.inavare.net/openscada/modules/bob/trunk/下找到源代码