我有一个有多个复制任务的目标;它基本上将常见的 jar 文件从集中位置复制到应用程序的 lib
文件夹中。
由于这是一项常规复制任务,只有当 jar 比 lib
文件夹中当前的 jar 更新时,才会复制该 jar。
这是 build.xml 中的相关部分:
<target name="libs"/>
<copy file=... />
<copy file=... />
<copy file=... />
<antcall target="clean_compiled_classes"/>
</target>
<target name="clean_compiled_classes" if="anyOfTheLibsWereCopied">
<delete .../>
</target>
我正在寻找一种方法,根据是否有任何文件实际更改,在 libs
目标中的 ant 调用之前设置 anyOfTheLibsWereCopied
属性。
谢谢,
伊泰
最佳答案
我建议看看 Uptodate任务。我以前从未使用过它,但我想您正在尝试做的事情将按照以下方式实现:
<target name="libs"/>
<uptodate property="isUpToDate">
<srcfiles dir="${source.dir}" includes="**/*.jar"/>
<globmapper from="${source.dir}/*.jar" to="${destination.dir}/*.jar"/>
</uptodate>
<!-- tasks below will only be executed if
there were libs that needed an update -->
<antcall target="copy_libs"/>
<antcall target="clean_compiled_classes"/>
</target>
<target name="copy_libs" unless="isUpToDate">
<copy file=... />
<copy file=... />
<copy file=... />
</target>
<target name="clean_compiled_classes" unless="isUpToDate">
<delete .../>
</target>
您的另一个选择是实现您自己的 ant 任务来执行您想要的操作。但这需要更多的工作。
关于java - Ant:如何知道十个复制任务中的至少一个复制任务是否真正复制了文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4533925/