ant 错误无法将旧文件重命名为临时文件

发布于 2024-08-23 01:05:27 字数 841 浏览 5 评论 0原文

我正在使用 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 error
Unable 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

各自安好 2024-08-30 01:05:27

经过一番实验,我找到了答案。通过将 fork="true" 添加到我的 javac 任务中,文件句柄将在任务结束时关闭。这使得我的 jar 修改能够在稍后的构建中成功。

但这很不幸,因为我必须记住将其添加到每个上游 javac 任务中。

So I found the answer, after some experimentation. By adding fork="true" to my javac 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.

小清晰的声音 2024-08-30 01:05:27

这是 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?

海之角 2024-08-30 01:05:27

此处针对完全相同的问题提交了一个错误。

他们说这个问题在 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

故人的歌 2024-08-30 01:05:27

我尝试了最新版本的 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

单调的奢华 2024-08-30 01:05:27

它似乎与类路径配置有关,并且对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文