You are being forwarded to the lastest updates ot his page!
Or you can Click Here if it doesn't work or you don't wish to wait.

unable to delete or rename old file

svein
When I try to either delete or update an existing .jar file my ant build fails with the message "Unable to delete file C:\ejb_titan\titan.jar" and "Unable to rename old file(C:\ejb_titan\titan.jar)".

I am using Windows XP and the same build file works fine on my laptop which also uses Windows XP. So I guess there is a problem with the setup of the machine I am using, but I am not able to figure it out.

BTW, I have seen the problem reported previously on this forum and also on a couple of other forums on the net but without any solution.

Any help will be much appreciated,

br
Sven

Here are the jar and clean targets.

code:
  <target name="jar" depends="compileserver">
<jar basedir="${basedir}/build/server"
includes="com/titan/"
destfile="${basedir}/${ant.project.name}.jar">
<metainf dir="${basedir}/deploy"/>
</jar>
<jar basedir="${basedir}/build/shared"
includes="com/titan/"
destfile="${basedir}/${ant.project.name}.jar"
update="true"/>
</target>

<target name="clean">
<delete dir="${basedir}/build"/>
<delete file="${basedir}/${ant.project.name}.jar"/>
<delete file="${JBOSS_HOME}/server/default/deploy/${ant.project.name}.jar"/>
</target>




bootedbear
Windows is very picky about file sharing. If it thinks something else has the file open (it's not always very good about keeping track), it will disallow the operation.

Do you have an IDE that could have the file open? A server (like Tomcat)?


svein
No, this happens also when no IDE or Tomcat is running. So there must be some other process using the file. How can I find out which ? I need to know which process to shut down in the Windows Task Manager (ctrl+alt+del).

BTW, I noticed that I can't remove the Read Only attribute from ANY folder on my system. Is it correct that WinXP just ignores this attribute ? And is there a way to remove it, I've tried right-clicking the file and accessing the File properties dialog.

Sven


Roseanne Zhang
Bear Bibeault is correct, I think. Windose makes a lot of decisions for you, even it is not always correct.

I was struggling with similar problems these two days. When ant cannot do it, then try use your hand to delete it, if you cannot, it is clear it is "Windose".

How to fight with your "Windose"? Try the followings in order:
1) Close all possible apps use that file/dir.
2) Close cmd or cygwin windows
3) Close Windows Explorer, then reopen.
4) If still not work, shut-down your PC, count 1 to 10, then start again. It worked

Haha

[ June 21, 2005: Message edited by: Roseanne Zhang ]


svein
I am able to delete the file manually, so the problem must in some way be related to Ant.

Having to delete the file manually every time you deploy becomes extremely tedious after a while.

Sven


jchitrady
I too was struggling for a long time and finally this is the solution for me which I think is applicable to some of us.
This is not related to windows have a lock on the file as the file can be renamed, deleted manually. I believe it is a bug in Ant itself.

See example below as illustration. If in your target tag your have a depends attribute to a target that refer to the jar file you want to update then you will have this issue. The solution is to remove it from the depends attribute, this would mean that you have to execute all the dependent targets manually first and then the target to build that jar file.

For example:

<target name="buildMyJar" depends="compile">
^^^^^^^^^^^^^^^^^^

<zip destfile="myJar.jar" basedir="${build}"
includes="com/xxx/order/**" update="true"/>
</target>

<target name""compile">
<javac srcdir="${src}" debug="on" destdir="${build}" includes="**"
classpath="${INSTALL_PATH}\lib\myJar.jar;"/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
</target>


To fix it then change the buildMyJar target to:

<target name="buildMyJar"> <<< remove the depend attribute
<zip destfile="myJar.jar" basedir="${build}"
includes="com/xxx/order/**" update="true"/>
</target>
And execute compile before buildMyJar separately. Till Ant is fixed, I think this is the best workaround.


Hope this helps.
Good luck.

[ July 02, 2005: Message edited by: Joe Chitrady ]

[ July 02, 2005: Message edited by: Joe Chitrady ]


Guy Allard
Your first suspect for what has the file locked should be your Antivirus package.

It has happened to me .......

Guy