ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: WELCOME to
Date Mon, 15 Jun 2015 03:51:17 GMT
On 2015-06-14, Christopher BROWN wrote:

> Since Java SE 7, URLClassLoader defines a "close()" method which may be
> useful in the specific case mentioned:

This won't help if the file in question is on the system classloader or
the classloader is going to be used later.

> As for the more general case of Windows locking files from Java, as I
> understand it, it's because the underlying file descriptor use to read from
> or write to files is only release when the associated stream is garbage
> collected (the logic is in the "finalize()" method).  In my own code, I
> have a utility "delete(File)" method that tries to delete the file, and if
> it fails (on a Windows system) will loop with 10 millisecond sleep
> intervals, on the second and last iterations attempting System.gc() to
> force finalization, and it is seems to be a robust workaround in practice.

Ant has similar code.  In 1.7.0 it was restricted to specific cases like
the Delete task, nowadays it is a helper method (tryHardToDelete in
FileUtils) that has been factored out and is used whenever a task wants
to delete a file.

Unfortunately it doesn't help for all cases (like files on the
classloader) and that's when the deleteOnExit work around we've added
comes into play.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message