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

查看:188
本文介绍了使用相同的目录名作为文件名的Ant解压/ unwar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Ant构建脚本来解压到Tomcat / webapps目录war文件。战争文件的名称是不固定的。我怎样才能将它解压缩目录中,其名称是一样的战争文件名。我知道如何解压缩文件,但问题是它解压缩在指定的目标目录的内容。如果我不知道是什么的目录名?

构建之前:

 的tomcat / webapps /目录
   对myApp-0.1.war

在构建后:

 的tomcat / webapps中
   对myApp-0.1 /
   对myApp-0.1.war


解决方案

尼斯工作 bluetech 。您的解决方案也可能是pssed前$ P $如下:

 <目标名称=unwar测试>
  <属性名=webapps.dirVALUE =雄猫/ webapps中/>  <文件集ID =war.file.idDIR =$ {} BASEDIR
      包括=$ {} webapps.dir /对myApp - *战争。/>
  <属性名=war.fileREFID =war.file.id/>  <战争的基本名称属性=war.basename文件=$ {} war.file后缀= />
  <属性名=unwar.dir位置=$ {webapps.dir} / $ {} war.basename/>
  < MKDIR DIR =$ {} unwar.dir/>
  < unwar DEST =$ {} unwar.dirSRC =$ {} war.file/>
< /目标与GT;

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?

before build:

tomcat/webapps/
   myApp-0.1.war

after the build:

tomcat/webapps
   myApp-0.1/
   myApp-0.1.war

解决方案

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解压/ unwar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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