简体   繁体   English

eclipse项目的JAR文件夹

[英]JAR file folder for eclipse projects

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. 我正在尝试为此工作空间中的引用项目创建一个集中文件夹(在我的eclipse工作区中的某种“元项目”中),用于常用的JAR文件。 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. 它应该类似于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). 我试图用这些jar文件创建一个用户库并在项目中引用它们但我仍然需要手动将每个新jar添加到用户库(并且不知道它是否被absoulute引用)和Tomcat(WTP)似乎没有把这些文件(运行方式 - >运行在服务器上)放入其类路径(我不想复制jar并将它们放入WEB-INF / lib)。 Any ideas? 有任何想法吗?

+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). 您为其他项目添加了“公共项目”(Java Build Path-> Projects,然后添加)。 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 Build Path-> Order and Export,然后检查所有jar)。

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? 如果Project X使用commons-logging-1.0但有人创建的Project Z真的需要commons-logging-1.1呢? Do you want your central folder to have copies of the same JAR for each possible version number? 您是否希望中央文件夹为每个可能的版本号提供相同JAR的副本?

Use a build tool like Maven or Ivy which will download and handle dependent JARs for you. 使用像Maven或Ivy这样的构建工具,它将为您下载和处理相关的JAR。 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-eclipse插件可以很好地为Eclipse生成.project / .classpath文件,它会自动将所有依赖的JAR放在构建路径上,m2eclipse也擅长处理Eclipse中的依赖项。

I think you should take a serious look at Maven. 我想你应该认真看看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. 您只需声明每个项目所依赖的“工件”,Maven将负责从存储库中获取JAR,将它们添加到构建类路径中,并将它们包含在WAR文件中。 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. 如果您想进行批量构建,则无需创建Ant“build.xml”文件:只需从命令文件运行“mvn”即可。

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. 我会考虑使用Ivy对Ant的扩展来管理这些东西,如果你想要这样做的话,它具有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. 把所有东西扔到一堆都会最终给你带来问题,因为当你突然有两个项目时你会遇到版本问题,其中一个使用创建THAT时可用的版本,另一个是bugfixed版本,而那些不是100%兼容。

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/下找到源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM