Ant:如何对目录中的每个文件执行命令? [英] Ant: How to execute a command for each file in directory?

查看:28
本文介绍了Ant:如何对目录中的每个文件执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Ant 构建文件中为目录中的每个文件执行命令.
我正在寻找独立于平台的解决方案.

I want to execute a command from an Ant buildfile, for each file in a directory.
I am looking for a platform-independent solution.

我该怎么做?

当然,我可以用某种脚本语言编写脚本,但这会给项目增加更多的依赖.

推荐答案

简短回答

与嵌套的

Foreach 需要 ant-contrib.

Foreach requires ant-contrib.

最近 ant-contrib 的更新示例:

Updated Example for recent ant-contrib:

<target name="foo">
  <foreach target="bar" param="theFile">
    <fileset dir="${server.src}" casesensitive="yes">
      <include name="**/*.java"/>
      <exclude name="**/*Test*"/>
    </fileset>
  </foreach>
</target>

<target name="bar">
  <echo message="${theFile}"/>
</target>

这将使用 ${theFile} 调用目标bar",生成当前文件.

This will antcall the target "bar" with the ${theFile} resulting in the current file.

这篇关于Ant:如何对目录中的每个文件执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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