我正在向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中条目的顺序
发布于 2019-08-07 21:31:07
我认为这是不可能的,因为Manifest在内部使用映射条目。而且,oracle提到排序在documentation中并不重要。我猜他们用的是HashMap。也许如果将Manifest扩展为使用LinkedHashMap,则顺序可能会得到保留。我找到了这个http://juneau.apache.org/site/apidocs-7.2.2/org/apache/juneau/utils/ManifestFile.html
发布于 2019-08-09 20:27:46
在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哪个IMHO给你提供了更好的视野
[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以了解更多选项。
https://stackoverflow.com/questions/57361040
复制相似问题