我需要一个Ant脚本,将一个文件夹复制到其他几个地方.作为一个优秀的顺从程序员,我不想重复自己.有没有办法采取这样的文件集:
<copy todir="${target}/path/to/target/1">
<fileset dir="${src}">
<exclude name='**/*svn' />
</fileset>
</copy>
Run Code Online (Sandbox Code Playgroud)
并将其存储fileset
在变量中以便可以重复使用?
Ric*_*ler 41
在文件集上声明id属性,然后在每个复制任务中引用它.
例如:
<project name="foo">
<fileset id="myFileSet" dir="${src}">
<exclude name='**/*svn' />
</fileset>
...
<target name="copy1">
<copy todir="${target}/path/to/target/1">
<fileset refid="myFileSet"/>
</copy>
</target>
<target name="copy2">
<copy todir="${target}/path/to/target/2">
<fileset refid="myFileSet"/>
</copy>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
Dav*_*ebb 29
Rich的答案可能更适合您的特定问题,但在Ant中重用代码的一般方法是<macrodef>
.
<macrodef name="copythings">
<attribute name="todir"/>
<sequential>
<copy todir="@{todir}">
<fileset dir="${src}">
<exclude name='**/*svn' />
</fileset>
</copy>
</sequential>
</macrodef>
<copythings todir="/path/to/target1"/>
<copythings todir="/path/to/target2"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20284 次 |
最近记录: |