Java MANIFEST.MF中条目的顺序
我正在像Maven一样向Java MANIFEST.MF中条目的顺序,java,maven,jar,manifest.mf,maven-jar-plugin,Java,Maven,Jar,Manifest.mf,Maven Jar Plugin,我正在像Maven一样向MANIFEST.MF添加条目 <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <index>true</index> <manifest> <addDefaultImpl
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>
...
maven jar插件
真的
真的
真的
GAV
${project.groupId}
${project.artifactId}
${project.version}
${project.packaging}
...
条目会出现,但顺序是任意的。这对于读取它们的脚本来说并不重要,但是对于喜欢查找某些内容的人来说,文件看起来很混乱。有没有办法确定
MANIFEST.MF
中条目的顺序?我认为这是不可能的,因为内部使用的是映射条目。而且,oracle提到在清单中排序并不重要。我想他们使用HashMap。也许如果清单扩展为使用LinkedHashMap,那么顺序可能会被保留。我发现,在Maven中,您无法轻松地“确定MANIFEST.MF中条目的顺序”。至少不是简单地通过翻转开关或配置之类的方式
它可以由一个Maven插件完成,该插件按照您想要的方式生成MANIFEST.MF,然后指示Maven jar插件从何处获取它。这是可行的,但不是超级容易。如果其他插件对Maven中MANIFEST.MF的生成做出假设,那么它也可能破坏其他插件
但如果你只关心“喜欢查找某些东西的人类”,那么我建议你看看。它是一个(无依赖性,大小约5Mb)库和命令行工具,可以处理JAR文件
一旦完成,您就可以使用它以人性化的格式列出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
查看以获取更多选项。在链接中
ObjectMap扩展LinkedHashMap