Link to home
Start Free TrialLog in
Avatar of scurtis_1
scurtis_1

asked on

How to force Ant to delete files?

Hi,

Can't find an Ant forum, so this seemed like the next best place?!?

I have the following Ant task:

  <target name="clean"
          description="Deletes all build output for project and sub-projects">
    <ant dir="core" target="clean" />
    <ant dir="webapp" target="clean" />
    <delete dir="${build.dir}" includeEmptyDirs="true" />
  </target>

which should clear all of my *.jar files in lib folders under core and webapp projects. Fairly self explanatory. The problem is that when I run my build script it always fails saying:

"Unable to delete file C:\core\lib\*.jar"

for example.

If I go into Windows Explorer I can simply delete the files manually so it doesn't appear to be references to the jars preventing them from being deleted?

Any ideas would be very welcome!! I can provide the entire build script if anyone wants it to help them work out what might be wrong.

Thanks
Scott Curtis
ASKER CERTIFIED SOLUTION
Avatar of bvanderveen
bvanderveen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scurtis_1
scurtis_1

ASKER

Thanks for your reply bvanderveen.

Does your script specify each individual file to delete? I don't want to do this as I want to always delete all of the jar files in my lib folder. Something like *.jar? I don't want to specify each file individually, as that makes maintainence a nightmare.

It just doesn't seem to let me delete the files through the script at the moment?
It can.  Looking at it, you can see I am deleting the stub and skeleton RMI classes I have built (elsewhere, these have been copied to another directory, and will screw things up if they are on my classpath).  But,

    <delete dir="${compile.outdir}/app"/>

will delete a directory and everything under it.

Looking at your build file, I think you need to delete files in your build directory and then delete directories under it.  Ant may not like deleting your build directory itself.

Try individual delete lines like:

    <delete dir="c:\core" includeEmptyDirs="true" />

I have found the Ant documentation somewhat helpful:
    http://ant.apache.org/manual/index.html

Subtle RTFM response there, bvanderveen:

>I have found the Ant documentation somewhat helpful:
>http://ant.apache.org/manual/index.html

;-)

I will take another look at the docs and see if I can find anything.

Thanks
I wasn't trying to be subtle.  Seriously, most open-source has completely crappy documentation, so, a lot of times we don't look.  Not sure how much it will help, but all the Ant tasks are there with examples.
Have you tried doing something like this:

<target name="clean"
          description="Deletes all build output for project and sub-projects">
    <ant dir="core" target="clean" />
    <ant dir="webapp" target="clean" />
    <delete>
          <fileset dir="${build.dir}" includes="**/*.*"/>
    </delete>
  </target>

This should delete everything in you ${build.dir} directory