Ant:如何为目录中的每个文件执行命令?

我想从Ant构建文件为目录中的每个文件执行命令。

我正在寻找与平台无关的解决方案。


我该怎么做呢?


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


梵蒂冈之花
浏览 651回答 3
3回答

繁花不似锦

简短答案<foreach>与嵌套一起使用<FileSet>Foreach需要ant-contrib。更新了最近的ant-contrib示例:<target name="foo">&nbsp; <foreach target="bar" param="theFile">&nbsp; &nbsp; <fileset dir="${server.src}" casesensitive="yes">&nbsp; &nbsp; &nbsp; <include name="**/*.java"/>&nbsp; &nbsp; &nbsp; <exclude name="**/*Test*"/>&nbsp; &nbsp; </fileset>&nbsp; </foreach></target><target name="bar">&nbsp; <echo message="${theFile}"/></target>这将用$ {theFile}调用目标“栏”,生成当前文件。

千巷猫影

基本上,由于没有<java>的扩展(还可以吗?),与<apply>扩展<exec>的方式相同,他建议使用<apply>(当然也可以在命令行中运行Java程序)这里有一些例子:&nbsp; <apply executable="java">&nbsp;&nbsp; &nbsp; <arg value="-cp"/>&nbsp;&nbsp; &nbsp; <arg pathref="classpath"/>&nbsp;&nbsp; &nbsp; <arg value="-f"/>&nbsp;&nbsp; &nbsp; <srcfile/>&nbsp;&nbsp; &nbsp; <arg line="-o ${output.dir}"/>&nbsp;&nbsp; &nbsp; <fileset dir="${input.dir}" includes="*.txt"/>&nbsp;&nbsp; </apply>&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP