Ant is not able to delete some files on windows

后端 未结 14 2394
我寻月下人不归
我寻月下人不归 2021-02-07 01:36

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 generate

相关标签:
14条回答
  • 2021-02-07 02:19

    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.

    0 讨论(0)
  • 2021-02-07 02:19

    I faced the same problem.
    I didn't have any classpath set to or antivirus running on my machine.
    However, the ANT version I was using was 32 bit and the JDK I installed was 64 bit.
    I installed a 32 bit JDK and the issue was resolved.

    0 讨论(0)
  • 2021-02-07 02:20

    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.

    0 讨论(0)
  • 2021-02-07 02:22

    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.

    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.

    0 讨论(0)
  • 2021-02-07 02:23

    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.

    0 讨论(0)
  • 2021-02-07 02:25

    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.
    0 讨论(0)
提交回复
热议问题