Bug 26108 - delete task fails for jar file in CWD on WNT
Summary: delete task fails for jar file in CWD on WNT
Status: RESOLVED DUPLICATE of bug 28046
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.0
Hardware: PC All
: P3 normal with 3 votes (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
: 29066 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-01-13 21:28 UTC by Stephen Bell
Modified: 2008-02-22 12:18 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Bell 2004-01-13 21:28:12 UTC
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.
Comment 1 Jan Mat 2004-01-14 07:16:27 UTC
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 ...
Comment 2 Stephen Bell 2004-01-14 19:12:13 UTC
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
$ 
Comment 3 Stephen Bell 2004-01-15 20:01:42 UTC
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.
Comment 4 Stephen Bell 2004-01-18 23:59:49 UTC
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.
Comment 5 Mariano Benitez 2004-02-13 01:09:26 UTC
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.)
Comment 6 Jacob Kjome 2004-03-01 03:37:22 UTC
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
Comment 7 antbugzilla.3.josh 2004-03-09 00:23:25 UTC
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>
Comment 8 Horst Scheruga 2004-03-19 21:52:21 UTC
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.
Comment 9 Tom Kenny 2004-05-18 17:28:19 UTC
*** Bug 29066 has been marked as a duplicate of this bug. ***
Comment 10 Denise 2004-09-16 20:13:51 UTC
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.
Comment 11 Peter Reilly 2004-09-17 08:08:50 UTC
Opps, I forgot to mark this as a duplicate.

*** This bug has been marked as a duplicate of 28046 ***