I would like to know if it is possible to write an Ant task (using some other library if necessary) to reduce a JAR file so that it contains only certain classes and those on which they depend.
For example, I have a JAR containing classes A, B, C and D, where A and B both extend C. D is independent of the others. What I would like to do is specify to an Ant task that I only need class B, and end up with a JAR file that contains only B and C.
I have seen this answer which provides a simple way to say "I don't want A and D", and I imagine that replacing "excludes" with "includes" would allow me to specify "I do want B and C" like this:
<jar destfile="stripped.jar">
<zipfileset src="full.jar" includes="path/B.class;path/C.class"/>
</jar>
...but is there a dependency-aware way of doing this so that I can say "I want B" but end up with a JAR that contains B and its dependencies?