mvn打包时添加信息(如git);对已编译好的war/jar, 通过命令查看这些信息。

原理

借助META-INF/MANIFEST.MF。

步骤

1. 修改pom文件

<?xml version="1.0" encoding="utf-8"?>

<build> 
  <finalName>warname</finalName>  
  <plugins> 
    <plugin> 
      <groupId>org.apache.maven.plugins</groupId>  
      <artifactId>maven-war-plugin</artifactId>  
      <version>3.0.0</version>  
      <configuration> 
        <archive> 
          <manifest> 
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 
          </manifest>  
          <manifestEntries> 
            <Build-Time>${maven.build.timestamp}</Build-Time> 
          </manifestEntries>  
          <manifestSections> 
            <manifestSection> 
              <name>git version</name>  
              <manifestEntries> 
                <Implementation-SCM-Revision>${buildNumber}</Implementation-SCM-Revision>  
                <Implementation-SCM-Branch>${scmBranch}</Implementation-SCM-Branch> 
              </manifestEntries> 
            </manifestSection> 
          </manifestSections> 
        </archive> 
      </configuration> 
    </plugin> 
  </plugins> 
</build>

2. 编译

mvn clean package -Dmaven.test.skip=true -P prod  -DscmBranch=master -DbuildNumber=git-1234567

3.查看

unzip -p warname.war  META-INF/MANIFEST.MF

 

相关文章:

  • 2021-10-19
  • 2021-10-19
  • 2021-10-19
  • 2021-11-04
  • 2021-12-07
  • 2021-11-08
  • 2022-02-07
猜你喜欢
  • 2021-12-26
  • 2021-12-07
  • 2021-11-08
  • 2021-10-16
  • 2021-12-26
  • 2021-11-23
相关资源
相似解决方案