使用AntBuilder在Groovy中压缩文件/目录

时间:2013-01-08 22:38:11

标签: ant groovy antbuilder

我正在尝试使用AntBuilder在Groovy中压缩文件和目录。我有以下代码:

def ant = new AntBuilder()
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:file.name)

这会压缩文件“blah.txt”,但不会压缩文件“New Text Document.txt”。我认为问题在于空间。我尝试了以下内容:

ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"${file.name}")
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"\"${file.name}\"")

以上都没有解决问题。我正在使用Ant因为它会压缩目录,而且我无法访问org.apache.commons.io.compression。

1 个答案:

答案 0 :(得分:5)

如果查看docs for the ant zip task,include参数将被描述为:

  

以逗号或空格分隔的必须包含的文件模式列表

所以你是对的,是空间分隔符打破了它......

您需要使用更长的路线才能使其发挥作用:

new AntBuilder().zip( destFile: "${file}.zip" ) {
  fileset( dir: './Testing' ) {
    include( name:file.name )
  }
}