java - How do I clean only those files from destDir that are no longer in my source dir using ant-javac -
i have requirement want clean file in destdir no longer present in sourcedir. ex: assume have class: student.java , college.java in sourcedir. running ant task first time generated student.class , college.class. now, if delete student.java sourcedir , add class 'employee.java , run ant-javac task, see new file, 'employee.class' generated in destdir, old file i.e 'student.class' still there though 'student.java' no longer exists in sourcedir. requirement delete files destdir no longer in source dir.
ps: know ant clean work clean destdir before compiling, due few limitations wrt application, cannot clean destdir before running javac
bit unusual point out, typical use case clean destdir
directory berfore compiling... may specific clean explicitly selecting resources no longer present in sources directory. may use selectors select resources delete. following snippet should clean destdir
if run before javac
task :
<delete> <!-- select classes not have related source file --> <fileset dir="${build.dir}" includes="**/*.class"> <not> <present targetdir="${src.dir}"> <!-- use regex mapper handle inner classes --> <regexpmapper from="^([^\$]*)(\$.*)?.class" to="\1.java"/> </present> </not> </fileset> </delete>
Comments
Post a Comment