<target name="scrub">
<taskdef name="scrub" classname="net.sourceforge.importscrubber.ant.ImportScrubberTask"/>
<scrub root="${sourceDir}"
format="nobreaks"
classRoot="${classesDir}"
sortjavalibshigh="true"
recurse="true"/>
</target>
Just declare the taskdef and invoke the task with whatever source file you want to
scrub. If you want to scrub a directory, put the directory name in the root
attribute. If you want to descend recursively from the root directory, use the
recurse="true" attribute. If you want the Java standard libraries
to appear at the top of the list of import statements, use the
sortjavalibshigh="true" attribute. You can specify the way to format
the import statements - either nobreaks or each. The default format is nobreaks.
Finally, you can specify an encoding to use with the encoding attribute.
Here's the Ant target I use to scrub my projects. Note that I compile the code with debug info first - which discourages the compiler from removing class references.
<target name="scrub">
<taskdef name="scrub"
classname="net.sourceforge.importscrubber.ant.ImportScrubberTask"/>
<javac
deprecation="false"
debug="true"
optimize="false"
srcdir="${sourceDir}"
destdir="${sourceDir}"
classpath="${libDir}bcel.jar;${libDir}junit.jar"/>
<scrub root="${sourceDir}" classRoot="${classesDir}" recurse="true"/>
<delete>
<fileset dir="${sourceDir}" includes="**/*.class"/>
</delete>
</target>