Cleaning up stale .class files using Apache Ant

一曲冷凌霜 提交于 2020-01-03 18:34:33

问题


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 something using Ant mappers and filesets etc. but I failed. Removing all .class files older than their respective source .java files would be acceptable, too.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/4099845/cleaning-up-stale-class-files-using-apache-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!