开发者

Cleaning up stale .class files using Apache Ant

How do I clean up stale .class files out of ${workdir} given set of existing .java files in ${srcdir}? By stale I mean .class files that were generated from now removed .java files. I have tried coming up with s开发者_Python百科omething using Ant mappers and filesets etc. but I failed. Removing all .class files older than their respective source .java files would be acceptable, too.


I'm pretty sure there's an ant task to kill .classes older than the .java...

Depend sounds close, and may actually do what you want, but this isn't its intended purpose. Given developmentalinsanity's answer however, this may be the only thing that will Actually Work.


The problem is determining whether a class file without an obviously corresponding source file is really stale.

Try this in a single file (A.java)

public class A{}
class B{}

This will result in both A.class and B.class. So, B.class would seem stale because of the missing java file. You'd probably get similar issues with any inner classes.

Safest bet if you want to make sure there's no old class files lying around would be just to delete them all.


As it’s just not possible to detect what’s stale and what’s not, most builds have a clean target (that’s also part of cleanbuild). The clean target, just removes all files from you’re build directory. This directory normally is unversioned (svn:ignore).

Not all files in you’re build will be the result of the compiler, for example .property files, these files can be stored in an alternative directory that will be copies in to the build directory. For example in a web application build you can store those files in /web/WEB-INF/classes and let Ant copy them into the build directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜