Ant 使用与文件名相同的目录名解压/解压
问题描述:
我需要使用 ANT 构建脚本在 tomcat/webapps 目录中解压一个 war 文件.战争文件名不是固定的.如何将其解压缩到名称与 war 文件名相同的目录中.我知道如何解压缩文件,但问题是它会解压缩指定目标目录中的内容.如果我不知道目录名称怎么办?
I need to unzip a war file in tomcat/webapps directory using ANT build script. The war file name is not fixed. How can I unzip it in a directory whose name is the same as the war file name. I know how to unzip the file but the problem is it unzips the content in the specified destination directory. What if I don't know the directory name?
构建前:
tomcat/webapps/
myApp-0.1.war
构建后:
tomcat/webapps
myApp-0.1/
myApp-0.1.war
答
干得好 bluetech.您的解决方案也可以表示如下:
Nice work bluetech. Your solution could also be expressed as follows:
<target name="unwar-test">
<property name="webapps.dir" value="tomcat/webapps" />
<fileset id="war.file.id" dir="${basedir}"
includes="${webapps.dir}/myApp-*.war" />
<property name="war.file" refid="war.file.id" />
<basename property="war.basename" file="${war.file}" suffix=".war" />
<property name="unwar.dir" location="${webapps.dir}/${war.basename}" />
<mkdir dir="${unwar.dir}" />
<unwar dest="${unwar.dir}" src="${war.file}" />
</target>