<p>I have an ant build that makes directories, calls javac and all the regular stuff. The issue I am having is that when I try to do a clean (delete all the stuff that was generated) the delete task reports that is was unable to delete some files. When I try to delete them manually it works just fine. The files are apparently not open by any other process but ant still does not manage to delete them. What can I do?</p>

[{'answer_id': 77491, 'author': 'BQ.', 'author_id': 4632, 'author_profile': 'https://Stackoverflow.com/users/4632', 'pm_score': 2, 'selected': False, 'text': '<p>You don\'t say if your build is run as the currently logged on user. If not, the fact that explorer.exe or other process has the directory shown can cause it to be locked as well. But deleting it in that same explorer.exe process would succeed. Try Unlocker from <a href="http://ccollomb.free.fr/unlocker/" rel="nofollow noreferrer">http://ccollomb.free.fr/unlocker/</a> to see what processes have the files/directories locked.</p>\n'}, {'answer_id': 77510, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 2, 'selected': False, 'text': '<p>Is there something from the Ant process that is holding the files (or directory) open?  This would cause the situation where you could delete them after running ant, but not during.  </p>\n'}, {'answer_id': 77548, 'author': 'Craig Trader', 'author_id': 12895, 'author_profile': 'https://Stackoverflow.com/users/12895', 'pm_score': 3, 'selected': False, 'text': '<p>It depends ...</p>\n\n<ul>\n<li>The Ant process doesn\'t have enough permissions to delete the files (typically because they were created by a different user, perhaps a system user).  Try running your Ant script as an administrative user, using Run As.</li>\n<li>Windows is really bad at cleaning up file locks when processes die or are killed; consequently, Windows thinks the file is locked by a process that died (or was killed).  There\'s nothing you can do in this situation other than reboot.</li>\n<li>Get better tools to inspect your system state.  I recommend downloading the <a href="http://technet.microsoft.com/en-us/sysinternals/default.aspx" rel="noreferrer">SysInternals</a> tools and using them instead of the default Windows equivalents.</li>\n</ul>\n'}, {'answer_id': 81222, 'author': 'Shimi Bandiel', 'author_id': 15100, 'author_profile': 'https://Stackoverflow.com/users/15100', 'pm_score': 5, 'selected': True, 'text': '<p>I encountered this problem once.\nIt was because the file i tried to delete was a part of a <strong>classpath</strong> for another task.</p>\n'}, {'answer_id': 9566907, 'author': 'Sergey', 'author_id': 141408, 'author_profile': 'https://Stackoverflow.com/users/141408', 'pm_score': 2, 'selected': False, 'text': '<p>Ant versions before 1.8.0 have a bug which leads to random errors during delete operation. Try using Ant 1.8.0 or newer.</p>\n\n<p>You can see the bug details here <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=45960" rel="nofollow">https://issues.apache.org/bugzilla/show_bug.cgi?id=45960</a></p>\n'}, {'answer_id': 12032987, 'author': 'Artem Nakonechny', 'author_id': 298552, 'author_profile': 'https://Stackoverflow.com/users/298552', 'pm_score': 3, 'selected': False, 'text': "<p>Using Ant Retry task has helped me.\nI've just wrapped it around the Delete Task.</p>\n"}, {'answer_id': 17351723, 'author': 'Sarel Botha', 'author_id': 35264, 'author_profile': 'https://Stackoverflow.com/users/35264', 'pm_score': 0, 'selected': False, 'text': "<p>I've been having this problem a lot lately and it's random. One time it works, the next time it doesn't work. I'm using NetBeans (in case that matters) and I've added a lot of extra tasks to build.xml. I was having this problem in the -post-jar task. It would happen when I call unjar on the file, then delete. I suspect that NB is trying to scan the jar and this causes the lock on it.</p>\n\n<p>What worked for me is to immediately rename the jar at the start of -post-jar and add a .tmp extension to it. Then I call unjar on the temp file. When I'm done I rename back to the desired jar name.</p>\n"}, {'answer_id': 17675788, 'author': 'Sudheer Palyam', 'author_id': 534832, 'author_profile': 'https://Stackoverflow.com/users/534832', 'pm_score': 0, 'selected': False, 'text': '<p>I too had the same problem and was tried of manually deleting the build directories. Finally I solved it by renaming the .jar artifact of my project to a different name from project name itself. For ex: my project was portal and my ant built script use to generate portal.jar, where eclipse ant was not able to delete this portal.jar. When i changed my build.xml to generate my .jar as portalnew.jar, eclipse was able to delete this portalnew.jar next time. Hope this helps.</p>\n'}, {'answer_id': 23909598, 'author': 'Vinila', 'author_id': 3683279, 'author_profile': 'https://Stackoverflow.com/users/3683279', 'pm_score': 2, 'selected': False, 'text': "<p>I faced the same problem.<br>\nI didn't have any classpath set to or antivirus running on my machine.<br>\nHowever, the ANT version I was using was 32 bit and the JDK I installed was 64 bit.<br>\nI installed a 32 bit JDK and the issue was resolved.</p>\n"}, {'answer_id': 25642430, 'author': 'MikeRoger', 'author_id': 459655, 'author_profile': 'https://Stackoverflow.com/users/459655', 'pm_score': 1, 'selected': False, 'text': '<p>In my case my ant clean was failing from Eclipse, unable to remove build files. I see this from time to time.  Usually succeeds on a repeat attempt. This time no. \nTried running ant clean from command line, failed Unable to delete"unable to delete". \nIt must have been Eclipse holding on to the problem file, when I exited Eclipse, cmd line was able to delete OK.</p>\n'}, {'answer_id': 27246020, 'author': 'maQbex', 'author_id': 3416893, 'author_profile': 'https://Stackoverflow.com/users/3416893', 'pm_score': 0, 'selected': False, 'text': '<p>You need to delete it manually in Windows. It worked for me. (Usually the files to be deleted are older versions of jar.. For example: if there exists httpcore.4.2.5.ja5r and httpcore.4.3.jar, it will try to delete 4.2.5.jar)</p>\n'}, {'answer_id': 45319304, 'author': 'priya', 'author_id': 3876624, 'author_profile': 'https://Stackoverflow.com/users/3876624', 'pm_score': 0, 'selected': False, 'text': '<p>i faced this issue as the file the ant was trying to delete was being used by some other service/process.\nI stopped the service, and then the ant build script did run through.</p>\n'}, {'answer_id': 49192466, 'author': 'ShivaKumar', 'author_id': 6203724, 'author_profile': 'https://Stackoverflow.com/users/6203724', 'pm_score': 0, 'selected': False, 'text': '<p>In my case, I stopped running Java process from Task Manager and re-run the Ant build file. The file was able to delete and build was successful.</p>\n'}, {'answer_id': 53188224, 'author': 'momo', 'author_id': 5118529, 'author_profile': 'https://Stackoverflow.com/users/5118529', 'pm_score': 0, 'selected': False, 'text': '<p>I am seeing problems like this way too often since I switched to Microsoft Windows 10. Renaming the file immediately before removing it solved it for me:</p>\n\n<pre><code>&lt;rename src="file.name" dest="file.name.old"/&gt;\n&lt;delete file="file.name.old" /&gt;\n</code></pre>\n'}, {'answer_id': 69431386, 'author': 'Milan Patel', 'author_id': 14627788, 'author_profile': 'https://Stackoverflow.com/users/14627788', 'pm_score': 0, 'selected': False, 'text': "<p>For me, I am using mac so I tried sudo before ant cmd, <code>sudo ant clean all</code> and it did work perfectly fine.</p>\n<p>As i've read javac will not have access to delete JAR files so you can either sudo it or find alternative.</p>\n"}]
['https://Stackoverflow.com/questions/77436', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8621/']