是否有用于监视目录更改的 ANT 任务?
这对我来说听起来有点牵强,但是是否有一个 ANT 任务来监视目录的更改,然后在目录更改时运行特定的 ANT 类?
It sounds a little far fetched to me, but is there an ANT task for watching a directory for changes and then running a particular ANT class when the directory changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果文件只能在监视目录中添加或更改,那么您可以使用这个简单的 OutOfDate 任务。
如果文件可以从监视目录中消失,那么您会遇到更复杂的问题,您可以通过创建监视目录的影子目录结构并检查其是否与监视目录一致来解决。此任务比较复杂,但我将为您提供一个创建影子目录的脚本,因为它并不简单:
创建影子目录后,我将把检查目录一致性的任务留给读者作为练习。
If files can only be added to or changed in the watched directory, then you can use this simple OutOfDate task from antcontrib.
If files can disappear from the watched-dir, then you have more complicated problem, that you can solve by creating shadow directory structure of the watched dir and checking if its consistent with the watched-dir. This task is more complex, but I'll give you a script to create a shadow directory, as it is not straight forward:
With shadow directory created, I'll leave the task of checking directory consistency as an exercise for the reader.
是的,有一个 Ant 任务可以执行此操作:
https://github.com/chubbard/WatchTask
需要1.7+。它可以监视任意数量的文件集,并根据其来自哪个文件集调用任何目标。
Yes there is an Ant Task that will do this:
https://github.com/chubbard/WatchTask
It requires 1.7+. It can watch any number of filesets, and invoke any target depending on which fileset it came from.
您也许可以使用
Waitfor
任务实现你想要的。它会阻塞,直到一个或多个条件(例如特定文件的存在)变为真。You might be able to use the
Waitfor
task to achieve what you want. It blocks until one or more conditions (such as the presence of a particular file) become true.您可以将 apply 任务与 文件集选择器
文件集将根据存储的 MD5 校验和检查文件是否有更改。您需要将 ANT 放入循环中才能重复运行此检查。这在 Unix 中很容易做到:
You can combine the apply task with a fileset selector
The fileset will check the files against a stored MD5 checksum for changes. You'll need to put ANT into a loop in order to repeatedly run this check. this is easy to do in Unix: