I'm looking for a tool which can remove unneeded classes from jar file (or include only needed ones).
I use maven-based dependency management and build fat jar using
sbt-assembly. However, the resultant jar is sometimes a bit too fat (e.g., when I have to include a part of
hadoop package). I am sure that I do not need most of this code (for example, because I use only filesystem and not the whole
mapreduce package), but by building fat jar I automatically include all the classes.
What I want to do is to either build a jar from only minimal set of classes (I'm open to switching from
sbt to any other tool that can do this) or removing not needed classes from an existing jar file.
By "not needed" I mean classes which are not imported neither from my main class nor from any of my main class' dependencies.
I am aware that such tools may fail in presence of reflection and other dark magic - this is fine for me, as long as the tool works with the typical scenario (
imported classes must be in the package, others have to be removed)
It's great if the tool is open source, but I can live with closed-source version as well, as long as it's not a web tool (corporate IP protection rules)