使用ant脚本读取jar文件中的版本信息
使用ant脚本读取jar文件中的版本信息
步骤1、下载并配置ant环境,下载ant-contrib-1.0b3.jar,拷贝ant-contrib-1.0b3.jar到ANT_HOME/lib下面
步骤2、编写build.xml脚本
<?xmlversion="1.0"?>
<projectname="VersionManager"default="all"basedir=".">
<!--Initializationvariables-->
<propertyenvironment="env"/>
<propertyname="lib.dir.home"value="${basedir}/lib"/>
<propertyname="unpackage.dir.home"value="${basedir}/unpackage"/>
<propertyname="build.dir"value="build"/>
<pathid="ant.contrib.lib">
<filesetdir="${env.ANT_HOME}/lib">
<includename="**/*jar"/>
</fileset>
</path>
<taskdefresource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathrefid="ant.contrib.lib"/>
</classpath>
</taskdef>
<taskdefname="foreach"classname="net.sf.antcontrib.logic.ForEach">
<classpath>
<pathrefid="ant.contrib.lib"/>
</classpath>
</taskdef>
<!--=============================-->
<targetname="all"depends="list-jar"description="Doesthewholeenchilada"/>
<targetname="unjar">
<unjarsrc="${lib.dir.home}/${jarName}"dest="${unpackage.dir.home}/${jarName}"/>
</target>
<targetname="echo-manifest"depends="unjar">
<loadfileproperty="test"srcFile="${unpackage.dir.home}/${jarName}/META-INF/MANIFEST.MF"encoding="GBK"/>
<echomessage="jarfilename:${jarName}"/>
<echofile="${basedir}/versionInfo.txt"message="jarfilename:${jarName}
"append="true"/>
<echomessage="${test}"/>
<echofile="${basedir}/versionInfo.txt"message="${test}"append="true"/>
</target>
<!--
<targetname="echo-many-manifest">
<foreachtarget="echo-manifest"param="jarName"list="commons-codec-1.3.jar;commons-dbcp-1.2.1.jar"delimiter=";"/>
</target>
-->
<targetname="list-jar">
<foreachlist=""target="echo-manifest"param="jarPathName"delimiter=",">
<filesetdir="${lib.dir.home}">
<includename="**/*.jar"/>
</fileset>
</foreach>
</target>
<propertyregexproperty="jarName"input="${jarPathName}"regexp="lib\\(.*)"select="\1"/>
</project>