ant脚本打jar包 自动获取时间以及项目svn版本号
1.关键代码,获取时间
<tstamp> <format property="touch.time" pattern="yyyy/MM/dd hh:mm" /> </tstamp>
2.获取本地svn版本
<target name="version" depends="init" > <typedef resource="com/googlecode/svntask/svntask.xml"> <classpath> <fileset dir="${lib}"> <include name="svnkit.jar"/> <include name="svntask.jar"/> </fileset> </classpath> </typedef> <svn> <info path="E:\worksapce2\ACService2" revisionProperty="revisionVersion" /> </svn> <property name="version" value="${revisionVersion}" />
<echo message="version: ${version}" /> </target>
3. 项目示例
<project name="build_pub" default="jar" basedir="."> <property name="class.dir" value="WEB-INF/classes"/> <property name="src.dir" value="src" /> <property name="build.dir" value="targetJar" /> <property name="jar.name" value="ac-api.jar" /> <property name="lib" value="WEB-INF/lib" /> <path id="classpath"> <fileset dir="${lib}" includes="**/*.jar"/> </path> <target name="init"> <echo message="+--- init start ---+" /> <tstamp /> <delete file="${build.dir}/${jar.name}" /> <echo message="+--- init end ---+" /> </target> <target name="version" depends="init" > <typedef resource="com/googlecode/svntask/svntask.xml"> <classpath> <fileset dir="${lib}"> <include name="svnkit.jar"/> <include name="svntask.jar"/> </fileset> </classpath> </typedef> <svn> <info path="E:\worksapce2\ACService2" revisionProperty="revisionVersion" /> </svn> <property name="version" value="${revisionVersion}" /> <echo message="version: ${version}" /> </target> <target name="jar" depends="version" > <echo message="+--- jar *.class files start ---+" /> <tstamp> <format property="touch.time" pattern="yyyy/MM/dd hh:mm" /> </tstamp> <pathconvert property="mf.classpath" pathsep="lib/"> <path refid="classpath" /> <flattenmapper /> </pathconvert> <jar destfile="${build.dir}/${jar.name}" update="true"> <fileset dir="${class.dir}" includes="com/inspur/api/ac/**,com/inspur/api/common/**"> </fileset> <manifest> <attribute name="user-name" value="liyx"/> <attribute name="svn-version" value="${version}"/> <attribute name="package-time" value="${touch.time}"/> </manifest> </jar> <echo message="+--- jar *.class files end ---+" /> </target> </project>
4.注意事项
注意target直接的依赖关系,另外获取本地svn号需要依赖本地jar包,分别是svntask.jar和svnkit.jar,我分享的下载地址分别为:
http://mobile.qzone.qq.com/l?g=1357&sharekey=7ab0de0e131e16e9d859dff5bc1c5ea9
http://mobile.qzone.qq.com/l?g=1357&sharekey=cdbeb37e11b4395fd3dad86edc02e197
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。