8

My project uses Java libraries that have their own dependencies (Hadoop, Jetty for example). I end up with different versions of the same dependencies, like ant 1.4.5, 1.4.6. My project may want to use ant 1.4.7. This is a small example, can get more complicated with larger dependencies like HTTP Commons.

How do I get all the libraries and dependencies to play nice? Is there a way to isolate each library (Hadoop, Jetty) so they only use their dependencies?

4

5 回答 5

2

您可以选择使用依赖管理框架(如 OSGI)来管理所有这些。看看spring框架动态模块http://www.springsource.org/osgi

您还可以查看 Eclipse 实现 OSGI 的框架部分。看看这里http://www.eclipse.org/osgi/

简短的回答就是寻找最小的公分母。请记住,'endorsed' 目录是您的朋友——在管理冲突的依赖项时。

于 2008-11-08T04:25:01.403 回答
2

Maven 通常也会很好地处理这个问题。如果不完全,它至少会处理大部分,然后你可以解决剩下的问题。

当然这意味着你必须改变你的构建过程,但你可能值得花点时间不要为此而烦恼。

于 2008-11-08T05:04:31.217 回答
2

JarJar来救援!

ant 认为 1) 将许多 jar 打包到一个中,2) 允许您重命名类文件中的依赖项,从而加载同一库的两个版本!

于 2008-11-10T04:03:54.503 回答
1

If you have the source code, compile everything together. If you don't, unfortunately you will have to target your source for the lowest-common-denominator with the target option to javac. You only have to do this if there are actual issues when running the application, which there rarely should be as long as the jvm is a current version (Java is very strict about binary compatibility with older versions).

于 2008-11-08T03:57:48.013 回答
0

JG 提到了 OSGi,这甚至是我在阅读这个问题时的第一个想法。

拥有同一个库的多个版本是 OSGi 的强项。如果我们已经提到了一些第三方产品,我认为提及其背后的规范也是公平的。

您可以从官方 osgi 网站http://osgi.org获取

于 2008-11-11T09:21:00.230 回答