Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant error Unable to rename old file to temporary file

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?

like image 513
karoberts Avatar asked Feb 20 '10 00:02

karoberts


4 Answers

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.

like image 178
karoberts Avatar answered Sep 20 '22 02:09

karoberts


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?

like image 41
Mark O'Connor Avatar answered Sep 22 '22 02:09

Mark O'Connor


There is a bug filed for the exact same issue here.

They are saying that this is fixed in Ant version 1.8

like image 42
Faisal Feroz Avatar answered Sep 21 '22 02:09

Faisal Feroz


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

like image 22
Sriragavan Natesan Avatar answered Sep 23 '22 02:09

Sriragavan Natesan