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条回答
小情绪 Triste *
2楼-- · 2020-05-31 05:39

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:

<rename src="file.name" dest="file.name.old"/>
<delete file="file.name.old" />
查看更多
The star\"
3楼-- · 2020-05-31 05:42

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.

查看更多
聊天终结者
4楼-- · 2020-05-31 05:44

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.

You can see the bug details here https://issues.apache.org/bugzilla/show_bug.cgi?id=45960

查看更多
时光不老,我们不散
5楼-- · 2020-05-31 05:45

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.

查看更多
霸刀☆藐视天下
6楼-- · 2020-05-31 05:46

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.

查看更多
淡お忘
7楼-- · 2020-05-31 05:46

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)

查看更多
登录 后发表回答