【问题标题】:Order of entries in MANIFEST.MFMANIFEST.MF 中的条目顺序
【发布时间】:2019-12-13 02:55:12
【问题描述】:

我正在向 Maven 中的 MANIFEST.MF 添加条目,例如

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
          <index>true</index>
          <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            <addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
          </manifest>
          <manifestSections>
            <manifestSection>
              <name>GAV</name>
              <manifestEntries>
                <GroupId>${project.groupId}</GroupId>
                <ArtifactId>${project.artifactId}</ArtifactId>
                <Version>${project.version}</Version>
                <Packaging>${project.packaging}</Packaging>
              </manifestEntries>
            </manifestSection>
            ...

条目出现,但顺序是任意的。这对于读取它们的脚本无关紧要,但对于喜欢查找某些东西的人来说,文件看起来很乱。有没有办法确定MANIFEST.MF中条目的顺序?

【问题讨论】:

    标签: java maven jar manifest.mf maven-jar-plugin


    【解决方案1】:

    您不能在 Maven 中轻松“确定 MANIFEST.MF 中条目的顺序”。至少不是简单地通过诸如翻转开关或配置之类的东西。

    它可以通过一个 Maven 插件来完成,该插件以您想要的方式生成 MANIFEST.MF,然后指示 maven-jar-plugin 从哪里获取它。这是可行的,但不是超级容易。如果他们对 Maven 中的 MANIFEST.MF 生成做出假设,它也可能会破坏其他插件。

    但是,如果您只关心“喜欢查找某些东西的人”,那么我建议您查看bnd。它是一个(无依赖,大小约为 5Mb) 库和命令行工具,可以对 JAR 文件发挥作用。

    一旦你download it,你可以用它来以人类友好的格式列出 MANIFEST.MF,方法是:

    → bnd print ~/.m2/repository/org/apache/maven/maven-core/3.5.0/maven-core-3.5.0.jar
    

    恕我直言,哪个给你更好的看法

    [MANIFEST maven-core-3.5.0]
    Archiver-Version                         Plexus Archiver
    Build-Jdk                                1.7.0_80
    Built-By                                 stephenc
    Created-By                               Apache Maven 3.3.9
    Implementation-Title                     Maven Core
    Implementation-Vendor                    The Apache Software Foundation
    Implementation-Vendor-Id                 org.apache.maven
    Implementation-Version                   3.5.0
    Manifest-Version                         1.0
    Specification-Title                      Maven Core
    Specification-Vendor                     The Apache Software Foundation
    Specification-Version                    3.5.0
    

    你所说的“混乱”的 MANIFEST.MF:

    → unzip -q -c ~/.m2/repository/org/apache/maven/maven-core/3.5.0/maven-core-3.5.0.jar META-INF/MANIFEST.MF
    Manifest-Version: 1.0
    Implementation-Vendor: The Apache Software Foundation
    Implementation-Title: Maven Core
    Implementation-Version: 3.5.0
    Implementation-Vendor-Id: org.apache.maven
    Built-By: stephenc
    Build-Jdk: 1.7.0_80
    Specification-Vendor: The Apache Software Foundation
    Specification-Title: Maven Core
    Created-By: Apache Maven 3.3.9
    Specification-Version: 3.5.0
    Archiver-Version: Plexus Archiver
    

    查看documentation of the "print" command 了解更多选项。

    【讨论】:

      【解决方案2】:

      我认为这是不可能的,因为Manifest 在内部与 Map 条目一起使用。而且,oracle documentation 提到排序在 Manifest 中并不重要。我想他们使用HashMap。也许如果 Manifest 被扩展为使用 LinkedHashMap,那么可能会保留顺序。我找到了这个http://juneau.apache.org/site/apidocs-7.2.2/org/apache/juneau/utils/ManifestFile.html

      【讨论】:

      • 在您的链接中ObjectMap extends LinkedHashMap&lt;String,Object&gt;
      猜你喜欢
      • 1970-01-01
      • 2011-06-11
      • 2014-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 2021-04-16
      相关资源
      最近更新 更多