2

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)

  • Beware of reflection and runtime linkage though, such a tool can only do so much. In principle Java can even load classes depending on user input. – Maarten Bodewes Jun 21 '17 at 0:35
2

Yes, this can be achieved with JBOSS TattleTale tool. Please see this post for more information: Remove unused JARS from project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.