是否存在监视目录更改的ANT任务?
这听起来有点牵强,但是有没有一个ANT任务可以监视目录的变化,然后在目录变化时运行一个特定的ANT类?您可以使用是否存在监视目录更改的ANT任务?,ant,directory,listener,watch,Ant,Directory,Listener,Watch,这听起来有点牵强,但是有没有一个ANT任务可以监视目录的变化,然后在目录变化时运行一个特定的ANT类?您可以使用任务来实现您想要的。它会一直阻止,直到一个或多个条件(如特定文件的存在)变为真。如果文件只能添加到监视目录或在监视目录中更改,则可以使用antcontrib中的此简单任务 <property name="watched-dir.flagfile" location="MUST be not in watched dir"/> <outofdate> &l
任务来实现您想要的。它会一直阻止,直到一个或多个条件(如特定文件的存在)变为真。如果文件只能添加到监视目录或在监视目录中更改,则可以使用antcontrib中的此简单任务
<property name="watched-dir.flagfile"
location="MUST be not in watched dir"/>
<outofdate>
<sourcefiles>
<fileset dir="watched-dir"/>
</sourcefiles>
<targetfiles>
<pathelement location="${watched-dir.flagfile}"/>
</targetfiles>
<sequential>
<!--Tasks when something changes go here-->
<touch file="${watched-dir.flagfile}"/>
</sequential>
</outofdate>
如果文件可以从监视的目录中消失,那么您就有了更复杂的问题,您可以通过创建监视的目录的阴影目录结构并检查其是否与监视的目录一致来解决这个问题。这项任务更复杂,但我将为您提供一个创建阴影目录的脚本,因为它不是简单的:
<property name="TALK" value="true"/>
<property name="shadow-dir"
location="MUST be not in watched dir"/>
<touch
mkdirs="true"
verbose="${TALK}"
>
<fileset dir="watched-dir">
<patterns/>
<type type="file"/>
</fileset>
<!-- That's the tricky globmapper to make touch task work -->
<globmapper from="*" to="${shadow-dir}/*"/>
</touch>
<!--
Due to how touch task with mapped fileset is implemented, it
truncates file access times down to a milliseconds, so if you
would have used outofdate task on shadow dir it would always
show that something is out of date.
Because of that, touching all files in ${shadow-dir} again fixes
that chicken and egg problem.
-->
<touch verbose="${TALK}">
<fileset dir="${shadow-dir}"/>
</touch>
创建了影子目录后,我将把检查目录一致性的任务留给读者作为练习。您可以将该任务与
是的,有一个Ant任务可以做到这一点:
它需要1.7+。它可以监视任意数量的文件集,并根据它来自哪个文件集来调用任何目标。但ant任务不会轮询。有没有办法让ant任务订阅目录以进行更改?你说的“订阅”是什么意思?是否监视文件系统事件?目标目录中的文件是否比源目录中的文件旧并不重要。我需要一个ant任务来监视目录,当我在编辑器中保存文件中的更改时,它将调用一个特定的ant任务。我还没有找到简单的解决方案,所以我暂时使用一个特定于bash的命令:“inoticoming--foreground./src/ant\;”没有许可证…:(@JethroLarson现在有了。似乎是在你评论的同一天添加的。)还不知道如何使用它,不知道在哪里找到JAR他们的引用,没有足够的文档。
<apply executable="somecommand" parallel="false">
<srcfile/>
<fileset dir="${watch.dir}">
<modified/>
</fileset>
</apply>
while true
> do
> ant
> sleep 300
> done