首页 > 代码库 > ant脚本打jar包 自动获取时间以及项目svn版本号

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="http://www.mamicode.com/${revisionVersion}" />
<echo message="version: ${version}" /></target>

3. 项目示例

<project name="build_pub" default="jar" basedir=".">	<property name="class.dir" value="http://www.mamicode.com/WEB-INF/classes"/>	<property name="src.dir" value="http://www.mamicode.com/src" />	<property name="build.dir" value="http://www.mamicode.com/targetJar" />	<property name="jar.name" value="http://www.mamicode.com/ac-api.jar" />	<property name="lib" value="http://www.mamicode.com/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="http://www.mamicode.com/${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="http://www.mamicode.com/liyx"/>				<attribute name="svn-version" value="http://www.mamicode.com/${version}"/>				<attribute name="package-time" value="http://www.mamicode.com/${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

 

ant脚本打jar包 自动获取时间以及项目svn版本号