用Maven隐藏清单条目 [英] Hiding manifest entries with maven
问题描述
使用maven构建jar文件时,它将在META-INF/MANIFEST.MF中创建一个清单文件.当前的内容是:
When building a jar file with maven, it will create a manifest file in META-INF/MANIFEST.MF. Its contents currently are:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: <my username>
Created-By: Apache Maven 3.1.0
Build-Jdk: 1.8.0_5
如何隐藏清单条目?特别是,我想隐藏"Built-By:"条目,因为我看不出罐子应该包含我的用户名的任何原因.
How can I hide manifest entries? In particular I would like to hide the "Built-By:" entry because I don't see any reason why a jar should include my username.
推荐答案
Alex Chernyshev的描述将其设置为空白答案.为了更好地控制MANIFEST.MF,您不应使用maven-archiver插件.
The maven-achiver plugin documentation seems pretty clear that you cannot remove properties, only set them to blank as described in Alex Chernyshev's answer. In order to get more control over the MANIFEST.MF you should not use the maven-archiver plugin.
一种替代方法是使用 maven antrun插件和 Ant Jar Task 来构建Jar.
One alternative would be to use the maven antrun plugin and the Ant Jar Task to build the Jar.
在pom.xml中:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<jar destfile="test.jar" basedir=".">
<include name="build"/>
<manifest>
<attribute name="Manifest-Version:" value="1.0"/>
</manifest>
</jar>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
另一种替代方法是使用 Maven exec插件直接调用Jar工具.
Another alternative is calling the Jar tool directly using the Maven exec plugin.
我不喜欢推荐antrun,因为我认为这是一个肮脏的技巧,但是看来maven-archiver不能满足您的要求.可能需要提出对maven-archiver的功能请求.
I don't like recommending antrun, as I think it's a dirty hack, but it seems that maven-archiver does not meet your requirements. It might be worth raising a feature request for maven-archiver.
2014-10-06提出了吉拉(Jira) MSHARED-362
2014-10-06 Raised Jira MSHARED-362
2018-06-18:更新了指向Jira和Maven Exec插件的链接
2018-06-18: Updated link to Jira and to Maven Exec plugin
2019年1月14日:修复了针对maven-archiver-3.4.0的目标
2019-01-14: Fix targeted for maven-archiver-3.4.0
这篇关于用Maven隐藏清单条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!