Ant is not able to delete some files on windows

23,244

Solution 1

I encountered this problem once. It was because the file i tried to delete was a part of a classpath for another task.

Solution 2

It depends ...

  • 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.
  • 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.
  • Get better tools to inspect your system state. I recommend downloading the SysInternals tools and using them instead of the default Windows equivalents.

Solution 3

Using Ant Retry task has helped me. I've just wrapped it around the Delete Task.

Solution 4

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.

Solution 5

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 http://ccollomb.free.fr/unlocker/ to see what processes have the files/directories locked.

Share:
23,244

Related videos on Youtube

Honza
Author by

Honza

Ruby, Java and C. But mainly I do just software.

Updated on July 09, 2022

Comments

  • Honza
    Honza almost 2 years

    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?

    • Sergey
      Sergey about 12 years
      What Ant version you are using?
    • matbrgz
      matbrgz over 11 years
      They can still be open when ant tries to remove them from a previous task
  • Richard A
    Richard A over 15 years
    I agree with point 3. sysinternals handle.exe is invaluable as a command line tool to analyse this sort of problem.
  • Snekse
    Snekse about 13 years
    Okay, so sysinternals shows me that javaw.exe has a handle on a file or directory, now what?
  • CMS
    CMS over 9 years
    @StefanSprenger you have to execute your tasks in the right order
  • Arashsoft
    Arashsoft over 8 years
    It is not always the reason for this problem. Sometimes you just have to restart your system and everything works fine. In this case, probably the reason is windows falsely thinks a process is using those files.
  • Anu Shibin Joseph Raj
    Anu Shibin Joseph Raj over 6 years
    same problem for me... worked after changing to 32-bit jdk... thanks bro
  • jumping_monkey
    jumping_monkey almost 4 years
    @ShimiBandiel, thanks, seems logical. I tried to move the file manually, and Windows 10 told me that it is being used by Eclipse. I close Eclipse, move the file, and resume my ant build. What annoys me is that i need that file on the classpath...