【问题标题】:What is Java jar META-INF/DEPENDENCIES and How its created?什么是 Java jar META-INF/DEPENDENCIES 以及它是如何创建的?
【发布时间】:2021-10-25 12:23:03
【问题描述】:

我在我的 jar 中看到我们有 META-INF/DEPENDENCIES 文件。

// ------------------------------------------------------------------
// Transitive dependencies of this project determined from the
// maven pom organized by organization.
// ------------------------------------------------------------------

htrace-core4


From: 'FasterXML' (http://fasterxml.com/)
  - Jackson-annotations (http://wiki.fasterxml.com/JacksonHome) com.fasterxml.jackson.core:jackson-annotations:bundle:2.4.0
    License: The Apache Software License, Version 2.0  (http://www.apache.org/licenses/LICENSE-2.0.txt)
  - Jackson-core (http://wiki.fasterxml.com/JacksonHome) com.fasterxml.jackson.core:jackson-core:bundle:2.4.0
    License: The Apache Software License, Version 2.0  (http://www.apache.org/licenses/LICENSE-2.0.txt)
  - jackson-databind (http://wiki.fasterxml.com/JacksonHome) com.fasterxml.jackson.core:jackson-databind:bundle:2.4.0
    License: The Apache Software License, Version 2.0  (http://www.apache.org/licenses/LICENSE-2.0.txt)

From: 'The Apache Software Foundation' (http://www.apache.org/)
  - Commons Logging (http://commons.apache.org/logging) commons-logging:commons-logging:jar:1.1.1
    License: The Apache Software License, Version 2.0  (http://www.apache.org/licenses/LICENSE-2.0.txt)

我的问题是

  • 这个文件是什么,它的内容为我的 jar 添加了什么?
  • 它是如何创建的?我们如何在我们的 maven jar 构建中指明我们要创建这个文件?

【问题讨论】:

  • 可能是this。它似乎是一个依赖列表,仅此而已。

标签: java maven jar dependencies meta-inf


【解决方案1】:

这个文件是什么,它的内容为我的 jar 添加了什么?

它是一个 Apache 特定文件,用于记录 JAR 文件对其他 JAR 文件的传递依赖关系。它还列出了他们的许可证。

根据Maven documentation

“Maven 项目提供了一组资源来帮助您构建符合 Apache 规则的 Java 资源。”

... 这个文件是生成的文件之一。我无法找到列出上述引用所指的“Apache 规则”的链接。 (如果你能找到链接,请评论!)

OpenJDK 官方 JAR 文件规范中没有提到“META-INF/DEPENDENCIES”文件。


它是如何创建的?我们如何在我们的 maven jar 构建中指明我们要创建这个文件?

它是使用 Maven 的“maven-remote-resources-plugin”生成的。下面是一个取自 Apache Maven 文档的示例配置:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-remote-resources-plugin</artifactId>
    <version>1.4</version>
    <executions>
      <execution>
        <goals>
          <goal>process</goal>
        </goals>
        <configuration>
          <resourceBundles>
            <!-- Will generate META-INF/DEPENDENCIES META-INF/LICENSE META-INF/NOTICE -->
            <resourceBundle>org.apache.apache.resources:apache-jar-resource-bundle:1.5-SNAPSHOT</resourceBundle>
            <!-- Will generate META-INF/DEPENDENCIES.txt META-INF/LICENSE.txt META-INF/NOTICE.txt -->
            <resourceBundle>org.apache.apache.resources:apache-jar-txt-resource-bundle:1.5-SNAPSHOT</resourceBundle>
            <!-- Will generate META-INF/DISCLAIMER  -->
            <resourceBundle>org.apache.apache.resources:apache-incubator-disclaimer-resource-bundle:1.2-SNAPSHOT</resourceBundle>
          </resourceBundles>
        </configuration>
      </execution>
    </executions>
  </plugin>

这可以添加到项目的 POM 文件中的适当位置。

有关详细信息,请参阅 Apache Maven 文档中的 Apache Resource Bundles 页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-09
    • 2015-01-27
    • 1970-01-01
    • 2011-05-30
    • 2013-01-24
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    相关资源
    最近更新 更多