ant 错误无法将旧文件重命名为临时文件
我正在使用 ant 1.8.0 和 java 1.6.0.17,我遇到了一个奇怪的问题。
在我的 build.xml 中,我有一个简单的任务来编译代码
<javac destdir="${dir.build.classes}" debug="on">
<classpath refid="classpath"/>
<src path="${dir.src.java}"/>
</javac>
在“classpath”中是一个 jar,将其命名为 library.jar
在后面的任务中,我需要向 < code>library.jar,我喜欢这样
<jar destfile="library.jar" update="true" duplicate="fail">
<fileset dir="${dir.build.classes}">
<include name="some/class/files"/>
</fileset>
</jar>
这将失败并出现错误 无法将旧文件 (library.jar) 重命名为临时文件
我在 javac 调用之前和之后陷入了对 handle.exe 的调用,并且我可以确认运行 ant 的 java 进程获取了文件句柄在javac调用期间到library.jar,并且它不会放弃它。这导致我后来尝试更新 jar 失败。
为什么即使在 javac 任务完成后,ant 仍会在类路径中保持打开的 jar 句柄?
I'm using ant 1.8.0 and java 1.6.0.17 and I'm running into a strange problem.
In my build.xml, I have a simple task that compiles the code
<javac destdir="${dir.build.classes}" debug="on">
<classpath refid="classpath"/>
<src path="${dir.src.java}"/>
</javac>
In the "classpath" is a jar, call it library.jar
In a later task, I need to add a few classes to library.jar
, which I do like this
<jar destfile="library.jar" update="true" duplicate="fail">
<fileset dir="${dir.build.classes}">
<include name="some/class/files"/>
</fileset>
</jar>
This will fail with the errorUnable to rename old file (library.jar) to temporary file
I stuck in a call to handle.exe before and after the javac call, and I can confirm that the java process running ant grabs a file handle to library.jar during the javac call, and it doesn't give it up. This causes my later attempt to update the jar to fail.
Why would ant keep a handle to the jar in a classpath open even after the javac task is complete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
经过一番实验,我找到了答案。通过将
fork="true"
添加到我的javac
任务中,文件句柄将在任务结束时关闭。这使得我的 jar 修改能够在稍后的构建中成功。但这很不幸,因为我必须记住将其添加到每个上游 javac 任务中。
So I found the answer, after some experimentation. By adding
fork="true"
to myjavac
task, the file handle is closed at the end of the task. This allows my jar modification to succeed later in the build.It's unfortunate though, because I have to remember to add this to every upstream javac task.
这是 Windows 锁定问题。任何读取该文件的进程/线程都会阻止它被重命名,这就是 zip 任务在更新现有 jar 文件时所做的事情。
我猜测文件句柄保持打开状态,因为您使用了类路径引用。如果您要显式设置 javac 任务的类路径,也许文件句柄可能会关闭?
This is a windows locking issue. Any process/thread reading the file will prevent it from being renamed, which is what the zip task is doing, when updating an existing jar file.
I'm guessing that the file handle is being kept open because your using a classpath reference. Maybe the file handles might be closed if you were to explicitly set the javac task's classpath?
此处针对完全相同的问题提交了一个错误。
他们说这个问题在 Ant 1.8 版本中已修复
There is a bug filed for the exact same issue here.
They are saying that this is fixed in Ant version 1.8
我尝试了最新版本的 ANT(1.10.7),它对我有用。
此问题已在 1.9.7 中解决
ant 中的 WHATSNEW
FileUtils.java
I tried latest version of ANT(1.10.7) and its works for me.
This issue has been solved in 1.9.7
WHATSNEW in ant
FileUtils.java
它似乎与类路径配置有关,并且对 jar 文件的第一个操作使其保持打开状态。
我通过删除“.”解决了这个问题。来自我的类路径环境变量。
It seems related to classpath configuration and The first operation on the jar file keeps it opened.
I've resolved this issue by removing "." from my classpath env variable.