Ant is not able to delete some files on windows

2020-05-31 05:11发布

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?

14条回答
太酷不给撩
2楼-- · 2020-05-31 05:23

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

查看更多
何必那么认真
3楼-- · 2020-05-31 05:24

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.

查看更多
淡お忘
4楼-- · 2020-05-31 05:25

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.

查看更多
做个烂人
5楼-- · 2020-05-31 05:30

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. Tried running ant clean from command line, failed Unable to delete"unable to delete". It must have been Eclipse holding on to the problem file, when I exited Eclipse, cmd line was able to delete OK.

查看更多
爷、活的狠高调
6楼-- · 2020-05-31 05:33

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.

查看更多
老娘就宠你
7楼-- · 2020-05-31 05:35

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.
查看更多
登录 后发表回答