20021226 Thursday December 26, 2002

Ant won't delete a file - any ideas? I've been experiencing this problem for the last couple of days. Basically, when I run "ant clean" on my project, I get the following error:

file:d:/source/appfuse/build.xml:746: 
  Unable to delete file D:\source\appfuse\dist\appfuse-common.jar

I can delete the "dist" directory in Explorer, and also using "rm -r dist" in Cygwin. Any ideas why Ant is choking on this all of a sudden? Posted in Java at Dec 26 2002, 05:05:32 PM MST 13 Comments

Comments:

Chances are that your build is using that JAR file in a classpath to <javac> or some other task, and Windows JVM locks JAR files from being deleted.

Posted by Erik Hatcher on December 26, 2002 at 11:02 PM MST #

Hmmm, even if nothing is running eh? They're referenced in my classpath, and I <em>believe</em> I got this code from your sample.

Posted by Matt Raible on December 27, 2002 at 11:18 AM MST #

I've seen this before - NetBeans (and Forte) grab onto jars from time to time and won't let go. I've never had the problem with Eclipse of IDEA.

Posted by Chris Reeves on December 27, 2002 at 11:25 AM MST #

I was able to fix it by removing the following from "ejb.compile.classpath" <code> <pathelement location="${dist.dir}/${webapp.name}-common.jar"/> </code> But since I still need my common classes in my classpath for compiling the "src/ejb" I added it to my "additional.src.dirs". <code> <param name="additional.src.dirs" value="${build.dir}/ejb/gen;src/common"/> </code> Erik - is this what you recommend?

Posted by Matt Raible on December 27, 2002 at 11:26 AM MST #

Yup, that looks good.

Posted by Erik Hatcher on December 29, 2002 at 04:36 AM MST #

Yeah, same thing happened with me. My main Ant build script (within eclipse) generates a jar file that is subsequently used by other build scripts. Those other child build scripts had a reference to the generated jar : <path id="module.class.path"> <pathelement location="${lib.dir}/${generated}.jar"/> </path> Once the child build script is invoked. The ${lib.dir}/${generated}.jar is locked (may be by Ant plugin within eclipse - not sure). So next time when I try to run my main build script it complains : unable to delete ${lib.dir}/${generated}.jar. The problem was solved by keeping two copies of the $(generated}.jar one in ${base.dir} and another in ${lib.dir} and refering ${base.dir}/${generated}.jar in classpath of child build script.

Posted by Yogesh on January 15, 2003 at 02:40 PM MST #

Yeah, same thing happened with me. My main Ant build script (within eclipse) generates a jar file that is subsequently used by other build scripts. Those other child build scripts had a reference to the generated jar
<path id="module.class.path">
<pathelement location="${lib.dir}/${generated}.jar"/>
</path>
Once the child build script is invoked. The ${lib.dir}/${generated}.jar is locked (may be by Ant plugin within eclipse - not sure). So next time when I try to run my main build script it complains : unable to delete ${lib.dir}/${generated}.jar.

The problem was solved by keeping two copies of the $(generated}.jar one in ${base.dir} and another in ${lib.dir} and refering ${base.dir}/${generated}.jar in classpath of child build script.

                

Posted by Yogesh on January 15, 2003 at 02:41 PM MST #

Behold my tale of woe:

I had the same problem just with my own homemade Ant script (not an Eclipse problem or anything like that). I tried everything from file access to voodo incantations and nothing seemed to work.

Then one day as I was just about to give up and explore a new career in vetrenary psycology, it dawned on me... Ant is written in Java! That means it uses classpath. That means if my .jar file is in the classpath than Ant's JVM is probably preloading it, and if its in use, then OF COURSE you can't delete it.

<div style="background:#ffff00">Sure enough, my classpath was ".;c:\jdk;yadda yadda" I removed the ".;" and it works every time!</div>

Well, Vaya Con Dios,
-Kurt

Posted by Kurt on October 26, 2004 at 10:46 AM MDT #

Waowwww ! Thank you Kurt ! I've been having headaches for months with this piece of ####.

Posted by Tom on February 04, 2005 at 09:01 AM MST #

Oh man, what a pain. I was trying to figure out why my clean wasn't deleting a jar file. It turned out that I had "." in my classpath, and the jar file was in my current directory...

Posted by Joel on February 17, 2005 at 11:07 AM MST #

I had a build.xml with <delete>, removing it( and only using owerwrite ) fixed this for me :)

Posted by Logi Helgu on September 06, 2005 at 07:18 AM MDT #

In fact, this is because you have execute some other .bat in the same dos window, some .bat script use the CLASSPATH which contains what you just want to delete in your ant build file. So you just need to open another DOS window to execute your ant task, it should be OK!

Posted by Zhao Ke on November 01, 2006 at 01:44 AM MST #

I had the same problem as Joel (February 17, 2005), namely that I had "." in my system classpath and Ant would not delete "foo.jar" from the current directory. Thanks, Joel and Kurt. But note: if I wanted to load classes from my jar, I would have had to put "./foo.jar" in my classpath, not just "."; is Ant adding *.jar to the classpath? If so, it is certainly doing me no favor. Is this a documented feature of Ant?

Posted by Bob P. on November 25, 2008 at 01:31 PM MST #

Post a Comment:
  • HTML Syntax: Allowed
Click me to subscribe
Matt Raible is a Web Architect who enjoys developing applications with open source technologies. Contact me for rates.
« December 2008
SunMonTueWedThuFriSat
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   
       
Today

Recent Entries

Tag Cloud