问题
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
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.
回答1:
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.
One alternative would be to use the maven antrun plugin and the Ant Jar Task to build the Jar.
In 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>
Another alternative is calling the Jar tool directly using the Maven exec plugin.
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.
EDIT: 2014-10-06 Raised Jira MSHARED-362
EDIT: 2018-06-18: Updated link to Jira and to Maven Exec plugin
EDIT: 2019-01-14: Fix targeted for maven-archiver-3.4.0
回答2:
Add
<addDefaultImplementationEntries>false</addDefaultImplementationEntries>
to configration section of maven-jar-plugin in your pom.xml to completely remove default properties:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>false</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
to customize it (remove just username):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Built-By></Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
回答3:
Set user.name
variable to empty string.
mvn -Duser.name="" package
Or if you are using Eclipse add -Duser.name=""
to VM arguments of Maven run configuration (Run -> Run As -> Maven build... -> JRE tab -> enter -Duser.name=""
in VM arguments field).
来源:https://stackoverflow.com/questions/25098307/hiding-manifest-entries-with-maven