需要每次打包的时候新建一个版本文件(eg:build.jsp)
1.创建模板版本文件:buildVersion.txt
@VERSIONID@.@PACKTIME@
2.追加maven-antrun-plugin组件:pom.xml
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.8,)</versionRange>
<goals>
<goal>compile</goal>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="******update version.jsp******" />
<tstamp>
<format property="TimeSign" pattern="yyMMddHHmmss" />
</tstamp>
<copy file="src/main/resources/buildVersion.txt"
tofile="src/main/webapp/WEB-INF/view/build.jsp"
overwrite="true" />
<replace file="src/main/webapp/WEB-INF/view/build.jsp"
summary="true" token="@PACKTIME@" value="${TimeSign}" />
<replace file="src/main/webapp/WEB-INF/view/build.jsp"
summary="true" token="@VERSIONID@" value="1.1" />
</target>
</configuration>
</execution>
</executions>
</plugin>
这里如果没有指定版本号,eclipse出现以下报错 但并不影响正常执行:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.8:run (execution: default, phase: compile) pom.xml Maven Project Build Lifecycle Mapping Problem