Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing jar file size? [duplicate]

Is there a good app to reduce jar file size by eliminating redundant classes/methods/constant pool elements? (i.e. not reachable from a fixed set of entry points, assuming no reflection)

I'm tired of pulling in bloated libraries when I'm just using a couple of methods from them.

(I'm not talking about small "local" optimizations like making names smaller. I'm thinking more of something that does global analysis to figure out which classes/methods/variables are used, given a set of entry points (including reflective entry points), and removes everything that is not used.

My webapp is like, 45MB, mostly due to 30-odd libraries, and I'm pretty sure I'm using only a small fraction of each library.

like image 810
user1001630 Avatar asked Oct 18 '11 16:10

user1001630


2 Answers

Yes, there is one - Proguard.

ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.

like image 87
om-nom-nom Avatar answered Sep 28 '22 08:09

om-nom-nom


Obfuscation typically reduces jar file size by a respectable factor.

You may want to try tools like Proguard (open source) and similar.

You can see some examples of size reduction in this page:

  • http://proguard.sourceforge.net/index.html#/results.html
like image 40
Grodriguez Avatar answered Sep 28 '22 08:09

Grodriguez