Apache ant deleting directories no matter what
How do I get Apache Ant to delete a directory no matter what. I want it to be deleted even if there are locks or usages of the directory on windows.
I am using a continuous integration remote agent on a Windows box which fails to delete the build directory and as a result fails the build. This is extremely annoying and is disruptive to the statistics.
There is nothing actively using the directory, and the antivirus is disabled.
I just want to delete the directory no matter what. How can I achieve that on Windows with A开发者_如何学Pythonpache Ant?
I think you will need external program to do this. check this one: _http://www.codeguru.com/cpp/w-p/files/fileio/article.php/c1287
here you have comparison of unlocking tools.Check this with command line interface: _http://ccollomb.free.fr/unlocker/
If you know what process is holding your folder you can just call taskkill...(you can even kill explorer.exe but and you can start it again) and if your folder is shared you can use net delete command
The best you can do in Ant is to set the parameters: quiet="true"
and includeemptydirs="true"
in order to prevent the build halting when the directory is missing or when a lock exists and to delete the top level directory even if it is empty. Eg:
<delete quiet="true" includeEmptyDirs="true">
<fileset dir="stubbornDir"/>
</delete>
You can also make sure that the resources you are attempting to delete are not read only, so include something like this in your script before your <delete>
task:
<!-- The following only works on UNIX -->
<chmod perm="a+w">
<fileset dir="${dist.dir}">
<include name="**/*.jar"/>
<exclude name="${app.context.path}"/>
</fileset>
</chmod>
<!-- Win NT alternative -->
<echo message=" To permit file deletion, execute attrib.exe to change read permissions on: ${dist.dir}"/>
<exec dir="${dist.dir}" executable="attrib.exe" os="Windows NT,Windows 2000,Windows XP">
<arg line="-R **/*.jar"/>
</exec>
But, to answer your question, I'm afraid, using Ant, it is not possible to delete files or directories when a lock exists.
However, also be aware, if you have used the <javac>
task earlier in your script, then unless you have set fork="true"
, the task will lock all files in your classpath and keep them locked during the entirety of your build.
Hope this helps!
精彩评论