maven项目打包发布的时候,使用插件实现自动生成一个版本号,用于标识发布的版本。
插件网站参考:http://www.mojohaus.org/buildnumber-maven-plugin/usage.html
一、在项目pom.xml文件中的project节点内添加buildnumber-maven-plugin插件
org.codehaus.mojo buildnumber-maven-plugin 1.4 {0,date,yyyy-MM-dd HH:mm:ss} - timestamp
validate create-timestamp src/main/resources true
二、在pom.xml文件properties节点的添加属性
${timestamp},与插件configuration中的item名称一致
${timestamp}
三、在项目的src/main/resources资源目录*.properties文件添加属性
在步骤“一”之中的resources实现编译时给src/main/resources的*.properties 文件属性赋值。当编译完成后,打开war包会发现${project.build.timestamp}会被赋值。
project.build.timestamp=${project.build.timestamp}
如果是时间戳模式,给properties 文件中的赋值是时间戳,在读取值之后再讲时间戳转换为日期。
四、在项目中读取*.properties文件中的值,将后台格式化之后的版本号返回到页面