什么是 Java jar META-INF/DEPENDENCIES 及其创建方式?

What is Java jar META-INF/DEPENDENCIES and How its created?

我在我的 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)

我的问题是

What is this file and what does its content add for my jar?

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

根据Maven documentation

"Maven project provides a set of resources to help you build Java resources compliant with Apache rules."

... 并且此文件是生成的文件之一。我一直没能找到 link 列出上述引用所指的“Apache 规则”。 (如果你能找到link,请评论!)

官方 OpenJDK JAR 文件规范中未提及“META-INF/DEPENDENCIES”文件。


How its created ? How do we indicate in our maven jar build that we want to create this file?

它是使用 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 页面。