查看jar/war的版本信息

前言

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

 

posted @ 2019-08-14 17:19  fly_pig  阅读(851)  评论(0编辑  收藏  举报