Search code examples
javajarhtmlunit

Determine used libraries to reduce JAR file size


I am using HtmlUnit in some programs and I always have the problem that whenever I use it, I have to add all the files (libraries) that I downloaded from HtmlUnit website so the jar file that I get is always 10 mb.

These are the files that I add:

alt text

But in most of my programs I only include this:

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.RefreshHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.*;

I usually only use WebClient and HtmlElements (HtmlForm, HtmlTable, etc.), so i find it strange that I need all of them.

My question is if I could reduce the number of libraries included, or maybe better, how can I determine which libraries that I include are not being used at all.


Solution

  • Do you really want to check all classes of all added libraries if they are needed or not?

    IMHO this is a job for program. One popular open source program for doing so is ProGuard.

    Generally ProGuard is known as obfuscator (rename everything in the class files so that understanding the decompiled classes is difficult) but it can be used without obfuscation when using the parameters -dontobfuscate. Additionally I suggest you to use the -dontoptimize parameter as well.

    If you run ProGuard on you big fat JAR you will get a much smaller one.

    If you are interested I could post a small part of an ant build file that shows how to configure and call ProGuard.