0

It seems to me that it would be really useful to have the dependencies of a jar listed in its Manifest, possibly as an optional field. Without this feature, it is near impossible to know what a jar depends on, without finding it on the web somewhere, or using a dependency management tool, or something along those lines. Now that everyone is using the whole artifact ID, group ID, version convention, I would imagine this would greatly simplify the tools needed to setup a project.

I find myself needing to use maven more than I would like to because it's such a hassle to figure out if something needs Apache commons or logging or whatever the case may be, why not just have the jars listed in some Manifest Field?

4

3 回答 3

1

看看 OSGI ( http://www.osgi.org/Main/HomePage )。除其他外,它还提供 jar 上的包(导入和导出语句)的依赖信息。

总体而言:依赖项通常并不简单直接(它们可能在范围、版本等方面有所不同)。来自 JEE 的 EAR 和 WAR 规范为应用程序服务器尝试了类似的东西。

于 2015-09-25T10:39:25.407 回答
1

因为依赖管理比最初看起来更难,所以 Java 没有提供一种机制。

如果要列出依赖项,则需要某种格式来描述每个依赖项。那必须是一个名称加上一个版本选择器。

Java 是跨平台的,所以名称不能是文件名,因为文件名是不可移植的。它不能是 JAR 的“名称”,因为某些实现可能分布在多个 JAR 上。名称必须是唯一的。谁来保证?

JAR 可能通过抽象 API 访问服务,因此可能需要实现,但不需要具体实现。那将如何表达?

一个 JAR 可能与另一个 JAR 的多个版本一起使用。那将如何表达?您如何表明它适用于一系列版本?版本 ID 很少是数字,因此没有明显的顺序。

于 2015-09-25T15:49:40.837 回答
1

我认为maven更方便。在清单中列出依赖项是非常模糊的,您没有指定诸如组、位置或存储库之类的元素,即使您对依赖项的名称没有安全性。

在清单中描述依赖是可能的,但是你如何引用这个依赖呢?它取决于每个开发人员,因此可能导致使用不同的名称、不同的 jar 包装等。

Maven 更复杂但也更准确,因为它定义了存储库、组、工件、版本和包,最终有助于减少歧义并允许您依赖可信赖的系统。

使用 maven 时,一个 pom 副本存储在 META-INF 目录中,您可以在这里找到依赖项。这比在清单中列出依赖项更有用。

于 2015-09-25T09:51:03.493 回答