You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by an...@quantel.com on 2011/07/14 18:37:34 UTC

Problem deleting a file

Hi,

I'm using ant 1.8.2 on Windows 7/64 bit

One of the tasks in my build script deletes a target file before it is 
rebuilt.
The trouble is the file doesn't actually seem to get deleted until after 
ant exits.
This causes ant to generate an error when it tries to create the new 
version of the file.

Below is the relevant bit of the build script in case there is something 
I'm doing wrong.
The file in question is Quentin.jar. If I have a window open on the 
directory containing
this file, I can see it doesn't get deleted until after ant exits. When 
this happens, ant
fails with the error

idl_compile:
     [echo] Creating Quentin JAR
      [jar] Building jar: P:\Quentin\Manager\Java\tmp\Quentin.jar
     [move] Moving 1 file to P:\Quentin\Manager\Java\jars

BUILD FAILED
P:\Quentin\Manager\build.xml:459: Failed to copy 
P:\Quentin\Manager\Java\tmp\Quentin.jar to 
P:\Quentin\Manager\Java\jars\Quentin.jar due to 
P:\Quentin\Manager\Java\jars\Quentin.jar (Access is denied)

Any help would be much appreciated

Regards

Andy Ling



        <target name="init" unless="init_done">
                <uptodate property="quentin_jar_ok" 
targetfile="${jar-files}\Quentin.jar">
                        <srcfiles dir="${root}/idl" 
includes="Quentin.idl"/>
                </uptodate>
                        <property name="init_done" value="true"/>
        </target>

        <target name="Quentin" if="docompile" depends="init">
                <javac includeantruntime="false" srcdir="${tmp-dir}" 
includes="com\quantel\Quentin\**" destdir="${outdir}" debug="${debug}" 
source="${source}">
                        <compilerarg line="${compiler_cmdline}"/>
                </javac>
        </target>

        <target name="idl_compile" if="docompile" depends="init,Quentin"/>

        <target name="idl_renew_src" depends="init">
                <delete dir="${tmp-dir}\com\quantel\Quentin"/>
                <delete file="${jar-files}\Quentin.jar"/>

                <!-- Make sources -->
                <echo>Building Quentin from IDL</echo>
                <exec executable="${env.JACORB_HOME}\bin\idl.bat">
                        <arg value="-all"/>
                        <arg value="-genEnhanced"/>
                        <arg value="-d"/>
                        <arg value="${tmp-dir}"/>
                        <arg value="-i2jpackage"/>
                        <arg value="Quentin:com.quantel.Quentin"/>
                </exec>
        </target>

        <target name="Quentin.jar" unless="quentin_jar_ok" depends="init">
                <antcall target="idl_renew_src"/>
                <antcall target="idl_compile"/>
                <echo>Creating Quentin JAR</echo>
                <jar jarfile ="${tmp-dir}\Quentin.jar">
                        <fileset dir="${outdir}">
                                <include 
name="com/quantel/Quentin/**/*.class" />
                        </fileset>
                </jar>
                <move file="${tmp-dir}\Quentin.jar" todir="${jar-files}"/>
        </target>



-- 

This e-mail is intended for the named addressees only. Its contents may be 
privileged or confidential and should be treated as such. If you are not 
an intended recipient please notify the sender immediately and then delete 
it;  do not copy, distribute, or take any action based on this e-mail. In 
the pursuit of its legitimate business activities and its conformance with 
relevant legislation, Quantel may access any e-mail (including 
attachments) it originates or receives, for potential scrutiny. 

Quantel is the trade name used by Quantel Holdings Limited and its 
subsidiaries.  Quantel Holdings Limited is registered in England & Wales. 
Registration No: 4004913 
Contact details for all Quantel Offices and Companies can be found on our 
website www.quantel.com or by writing to the holding company.
Registered address: Turnpike Road, Newbury, Berkshire, RG14 2NX, United 
Kingdom 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Problem deleting a file

Posted by an...@quantel.com.
Stefan Bodewig <bo...@apache.org> wrote on 15/07/2011 04:24:46:

> Is Quentin.jar on the CLASSPATH or loaded via <classpath> or similar
> measures during the build process?  If so Java's classloader probably
> still has a lock on it and Windows won't delete it until Ant exits.
> 

I thought I'd been round that, but you're right, it was still getting
put in the classpath.

Strange that the delete doesn't generate an error, it just seems to
delay it until it can happen.

Anyway, sorting out the CLASSPATH seems to have fixed things.

Thanks

Andy Ling



-- 

This e-mail is intended for the named addressees only. Its contents may be 
privileged or confidential and should be treated as such. If you are not 
an intended recipient please notify the sender immediately and then delete 
it;  do not copy, distribute, or take any action based on this e-mail. In 
the pursuit of its legitimate business activities and its conformance with 
relevant legislation, Quantel may access any e-mail (including 
attachments) it originates or receives, for potential scrutiny. 

Quantel is the trade name used by Quantel Holdings Limited and its 
subsidiaries.  Quantel Holdings Limited is registered in England & Wales. 
Registration No: 4004913 
Contact details for all Quantel Offices and Companies can be found on our 
website www.quantel.com or by writing to the holding company.
Registered address: Turnpike Road, Newbury, Berkshire, RG14 2NX, United 
Kingdom 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Problem deleting a file

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-07-14, <an...@quantel.com> wrote:

> One of the tasks in my build script deletes a target file before it is
> rebuilt.  The trouble is the file doesn't actually seem to get deleted
> until after ant exits.  This causes ant to generate an error when it
> tries to create the new version of the file.

> Below is the relevant bit of the build script in case there is
> something I'm doing wrong.  The file in question is Quentin.jar.

Is Quentin.jar on the CLASSPATH or loaded via <classpath> or similar
measures during the build process?  If so Java's classloader probably
still has a lock on it and Windows won't delete it until Ant exits.

>         <target name="Quentin" if="docompile" depends="init">
>                 <javac includeantruntime="false" srcdir="${tmp-dir}"
> includes="com\quantel\Quentin\**" destdir="${outdir}" debug="${debug}"
> source="${source}">
>                         <compilerarg line="${compiler_cmdline}"/>
>                 </javac>
>         </target>

This could be a candidate (depending on ${compiler_cmdline}), forking
javac would help in this case.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org