Ant 无法删除 Windows 上的某些文件
我有一个 ant 构建,可以创建目录、调用 javac 和所有常规内容。 我遇到的问题是,当我尝试执行清理(删除生成的所有内容)时,删除任务报告无法删除某些文件。 当我尝试手动删除它们时,效果很好。 这些文件显然没有被任何其他进程打开,但 ant 仍然无法删除它们。 我能做些什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
对我来说,我使用的是 mac,所以我在 ant cmd 之前尝试了 sudo,
sudo ant clean all
并且它工作得很好。正如我所读到的,javac 将无权删除 JAR 文件,因此您可以使用 sudo 或寻找替代方案。
For me, I am using mac so I tried sudo before ant cmd,
sudo ant clean all
and it did work perfectly fine.As i've read javac will not have access to delete JAR files so you can either sudo it or find alternative.
您没有说明您的构建是否以当前登录的用户身份运行。 如果没有,explorer.exe 或其他进程具有显示的目录这一事实也可能导致它被锁定。 但在同一个 explorer.exe 进程中删除它将会成功。 尝试使用 http://ccollomb.free.fr/unlocker/ 中的 Unlocker 查看哪些进程具有文件/目录已锁定。
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.
Ant 进程中是否有某些东西使文件(或目录)保持打开状态? 这会导致您可以在运行 ant 后删除它们,但不能在运行期间删除它们。
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.
我也遇到了同样的问题。
我的计算机上没有设置任何类路径或运行防病毒软件。
但是,我使用的 ANT 版本是 32 位,而我安装的 JDK 是 64 位。
我安装了32位JDK,问题解决了。
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.
1.8.0 之前的 Ant 版本有一个 bug,会导致删除操作期间出现随机错误。 尝试使用 Ant 1.8.0 或更高版本。
您可以在此处查看错误详细信息 https://issues.apache.org/bugzilla/ show_bug.cgi?id=45960
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
就我而言,我的 ant clean 在 Eclipse 中失败,无法删除构建文件。 我时常看到这一点。 通常重复尝试就会成功。 这次没有。
尝试从命令行运行 ant clean,失败无法删除“无法删除”。
肯定是 Eclipse 保留了问题文件,当我退出 Eclipse 时,cmd 行就可以删除了。
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.
我最近经常遇到这个问题,而且是随机的。 一次有效,下一次就无效了。 我正在使用 NetBeans(如果重要的话),并且我已经向 build.xml 添加了很多额外的任务。 我在 -post-jar 任务中遇到了这个问题。 当我对文件调用 unjar 然后删除时会发生这种情况。 我怀疑 NB 正在尝试扫描 jar,这会导致它被锁定。
对我有用的是立即在 -post-jar 开头重命名 jar 并为其添加 .tmp 扩展名。 然后我对临时文件调用 unjar。 完成后,我将其重命名回所需的 jar 名称。
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.
我也遇到了同样的问题,并尝试手动删除构建目录。 最后,我通过将项目的 .jar 工件重命名为与项目名称本身不同的名称来解决这个问题。 例如:我的项目是portal,我的ant构建脚本用于生成portal.jar,其中eclipse ant无法删除这个portal.jar。 当我更改 build.xml 以将 .jar 生成为 Portalnew.jar 时,Eclipse 下次能够删除此 Portalnew.jar。 希望这可以帮助。
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.
您需要在 Windows 中手动删除它。 这对我有用。 (通常要删除的文件是旧版本的jar。例如:如果存在httpcore.4.2.5.ja5r和httpcore.4.3.jar,则会尝试删除4.2.5.jar)
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)
我遇到这个问题,因为蚂蚁试图删除的文件正在被其他一些服务/进程使用。
我停止了服务,然后 ant 构建脚本确实运行了。
i faced this issue as the file the ant was trying to delete was being used by some other service/process.
I stopped the service, and then the ant build script did run through.
就我而言,我停止从任务管理器运行 Java 进程并重新运行 Ant 构建文件。 该文件能够删除并且构建成功。
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.
自从我切换到 Microsoft Windows 10 以来,我经常看到这样的问题。在删除文件之前立即重命名该文件为我解决了这个问题:
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:
这取决于...
It depends ...
使用 Ant Retry 任务对我有帮助。
我刚刚将其包裹在删除任务中。
Using Ant Retry task has helped me.
I've just wrapped it around the Delete Task.
我遇到过一次这个问题。
这是因为我尝试删除的文件是另一个任务的类路径的一部分。
I encountered this problem once.
It was because the file i tried to delete was a part of a classpath for another task.