Hiding manifest entries with maven

前端 未结 3 2305
执念已碎
执念已碎 2021-02-19 23:02

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                            


        
相关标签:
3条回答
  • 2021-02-19 23:42

    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>
    
    0 讨论(0)
  • 2021-02-19 23:50

    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

    0 讨论(0)
  • 2021-02-19 23:54

    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).

    0 讨论(0)
提交回复
热议问题