You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mighty Tornado <mi...@gmail.com> on 2009/04/29 20:03:06 UTC

remove old .class files

Hi,
Can I run the <javac> command in such a way that if I deleted java file
which was previously compiled, it will remove its .class file from the
classes directory when it builds again?

Thanks,

Ramy.

Re: remove old .class files

Posted by David Weintraub <qa...@gmail.com>.
On Wed, Apr 29, 2009 at 2:03 PM, Mighty Tornado
<mi...@gmail.com> wrote:
> Can I run the <javac> command in such a way that if I deleted java file
> which was previously compiled, it will remove its .class file from the
> classes directory when it builds again?

That's a limit on how Java works. The Java compiler compares the
timestamp on the resulting classfile with the source file. If the
timestamp on the source is older than the classfile, it doesn't do a
build.

However, this is a one way check: Checking a *.java source against its
*.class object. The Java compiler doesn't go through all the
classfiles and see if there is a corresponding source file. In fact,
it may be almost impossible for this to happen since there isn't
necessarily always a one-to-one correspondence between a source file
and object file.

There is also a problem of knowing where the source is stored since it
is quite common to place the compiled classfiles into their own
directory.

That's why God  created the "ant clean" command. (You do have a
"clean" target in your build.xml file. Right?

-- 
David Weintraub
qazwart@gmail.com

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