Ant 使用与文件名相同的目录名解压/解压 [英] Ant unzip/unwar with the same directory name as the file name

查看:39
本文介绍了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>

这篇关于Ant 使用与文件名相同的目录名解压/解压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆