Skip to content

Instantly share code, notes, and snippets.

@bohrqiu
Last active December 31, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bohrqiu/8036586 to your computer and use it in GitHub Desktop.
Save bohrqiu/8036586 to your computer and use it in GitHub Desktop.
maven打包时,自动生成静态资源版本号
1.在web项目pom里面添加build插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<includes>
<include>WEB-INF/velocity/layout/header.vm</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
<excludes>
<include>WEB-INF/velocity/layout/header.vm</include>
</excludes>
</resource>
</webResources>
</configuration>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</plugin>
上面对WEB-INF/velocity/layout/header.vm文件使用maven的过滤替换
2.在web项目的pom properties 中加入参数
<webapp.build.version>${maven.build.timestamp}</webapp.build.version>
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
这个配置定义了一个时间格式,然后把时间格式赋值到webapp.build.version变量
3.在header.vm中增加
<span id="code_version" style="display:none;">v${webapp.build.version}</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment