Could you have a look at this? Create a legit jar file, say build.jar, in the current directory on Windows NT4, then process a build file like this: <project default="clean"> <target name="clean"> <delete> <fileset dir="." includes="build.jar"/> </delete> </target> </project> The delete fails. I looked at this with filemon, and I suspect that build.jar is open at the time the delete happens. Worked OK at 1.5.4.
I extended your buildfile for tests: <project default="clean"> <target name="create"> <jar destfile="build.jar" includes="build.xml"/> </target> <target name="clean"> <echo>Using ${ant.version}</echo> <delete> <fileset dir="." includes="build.jar"/> </delete> </target> </project> And tried that with several Ant versions (one ant invocation for creating and another one for deleting): clean: [echo] Using Apache Ant version 1.7alpha compiled on November 18 2003 [delete] Deleting 1 files from C:\temp\xxx BUILD SUCCESSFUL clean: [echo] Using Apache Ant version 1.5.4 compiled on August 12 2003 [delete] Deleting 1 files from C:\temp\xxx BUILD SUCCESSFUL clean: [echo] Using Apache Ant version 1.6beta2 compiled on October 16 2003 [delete] Deleting 1 files from C:\temp\xxx BUILD SUCCESSFUL clean: [echo] Using Apache Ant version 1.6beta3 compiled on December 5 2003 [delete] Deleting 1 files from C:\temp\xxx BUILD SUCCESSFUL clean: [echo] Using Apache Ant version 1.6.0 compiled on December 18 2003 [delete] Deleting 1 files from C:\temp\xxx BUILD SUCCESSFUL Mmmh ... oh: I´m working on a W2K computer. So someone has to test that against a NT4. Don´t know if I´ll find one ...
That's a shame; I hoped it would recreate easily. Here's a run with your build file on a Win 2K box. (I've tried not under Cygwin and with more conventional JDK on Win NT, with the same result, so I don't think that's anything to do with it.) $ ant -verbose clean Apache Ant version 1.6.0 compiled on December 18 2003 Buildfile: build.xml Detected Java version: 1.3 in: f:\WebSphere\AppServer\java\jre Detected OS: Windows 2000 parsing buildfile f:\temp\vtemp\build.xml with URI = file:///F:/temp/vtemp/build.xml Project base dir set to: F:\temp\vtemp Build sequence for target `clean' is [clean] Complete build sequence is [clean, create, ] clean: [echo] Using Apache Ant version 1.6.0 compiled on December 18 2003 [delete] Deleting 1 files from F:\temp\vtemp [delete] Deleting F:\temp\vtemp\build.jar BUILD FAILED F:\temp\vtemp\build.xml:8: Unable to delete file F:\temp\vtemp\build.jar at org.apache.tools.ant.taskdefs.Delete.removeFiles(Delete.java:651) at org.apache.tools.ant.taskdefs.Delete.execute(Delete.java:540) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306) at org.apache.tools.ant.Task.perform(Task.java:401) at org.apache.tools.ant.Target.execute(Target.java:338) at org.apache.tools.ant.Target.performTasks(Target.java:365) at org.apache.tools.ant.Project.executeTarget(Project.java:1237) at org.apache.tools.ant.Project.executeTargets(Project.java:1094) at org.apache.tools.ant.Main.runBuild(Main.java:669) at org.apache.tools.ant.Main.startAnt(Main.java:220) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90) Total time: 3 seconds db2admin@CARBON /cygdrive/f/temp/vtemp $
Found out something a bit more pertinent, I think. My CLASSPATH was starting with ".". Don't know why I thought that was a good idea. Still, I don't think the failure happened with 1.5.4.
Yes, checked and it doesn't happen with 1.5.4. My very inexpert suggestion is that it's to do with ant now being invoked via org.apache.tools.ant.launch.Launcher, constructing a ClassLoader which hangs on to a handle to the file I want to delete. Anyhow, no big deal, as I don't need "." in my classpath anyway.
This may not sound very common, but I use the same ant to build the jars that are in the ant -lib <dir> in 1.6, so when I try to delete them, it fails. The problem is that I cannot change the ant script/env to remove the -lib ONLY when I am building those jars. I am just asking for a File.deleteOnExit() option for <delete>. (this may not be the bug to post this, but sounds like the problem you had is related.)
This affects the Log4j build and is very reproduceable using Ant-1.6.0 and 1.6.1. Works fine with Ant-1.5.3-1. When trying to run "ant chainsaw", existing log4j.jar and chainsaw.jar files are deleted and recreated before running chainsaw (a log viewer utility). The build fails on the deletes of the jars. To test this out, follow instructions here: http://logging.apache.org/log4j/docs/chainsaw.html Specifically, download the "install-chainsaw.xml" which will download dependencies (jakarta-oro) and grab the log4j CVS. Then cd into the "logging-logj" module and type "ant chainsaw". The first time it will work since the jar files won't have existed yet. All subsequent times it fails to delete the jars and breaks the build. Note: I do have a "." in my system classpath. I haven't tried removing it. Is it really the problem though? Jars don't get added to the classpath unless absolutely specified. They don't get put in the classpath simply by being in a directory in the classpath. Anyway, it would be great if this could be fixed. Jake
maybe not directly related, but I was building jar files into a directory that I had used in a "path" tag, and was unable to delete them until I specifically excluded the files from the path. before: <path id="mypath"> <fileset dir="${lib.dir}"> <include name="*.jar"/> </fileset> </path> after: <path id="mypath"> <fileset dir="${lib.dir}"> <include name="*.jar"/> <exclude name="fileIWantToDelete.jar"/> </fileset> </path>
I cannot delete any jar file with ant 1.6.2 No problem with 1.5.4 Uses following simple build file <project name="ci" default="make"> <property name="JarFile" value="plot.jar"/> <!-- ClassPath Definition --> <property name="build.sysclasspath" value="ignore"/> <target name="jar"> <delete file="${JarFile}"/> </target> </project> It seems to depend on the System Classpath. If the directory where the jar file exists is set in the CLASSPATH it fails.
*** Bug 29066 has been marked as a duplicate of this bug. ***
Just wanted to add that I have seen this same issue in versions 1.6.0 and later (I also tested 1.6.1 and 1.6.2) and I am on Windows XP. I removed the "." from my system CLASSPATH and it resolved it for me as well. Ant 1.5.4 worked fine with the "." in the CLASSPATH. I only seem to have a problem deleting .jar files, in one of my tests I called my file something else and it seemed to be deleted fine.
Opps, I forgot to mark this as a duplicate. *** This bug has been marked as a duplicate of 28046 ***