This question already has an answer here:
-
Java - How to reduce the size of third-party jars to reduce the size of your application
3 answers
I need to remove unused classes from third party JARs. Why tools should I use?
I already tried to use ProGuard. However, it removes only unused classes from the project itself but the library jars - third party - always remain unchanged.
You can create an uber jar and then use ProGuard. Repackaging library classes into jars would be a challenge, but from the spirit of your question you will prefer the uber jar as such.
As other posters have commented, you still need to be careful about classes loaded through the so much abused and misunderstood reflection mechanism.
@Joonas Pulakka is right. But if you still really want to do this and be sure that your application will not fail for ClassNotFoundException
run your application with option -verbose:class, perform all usecases that exist, take the log that contains all loaded classes. Then take list of all classes of your third party library and file all classes from your library that have been never loaded. Then create alternative jar file that contains only "needed" classes and pray :)
Good luck.
It is a good thing to know what classes and libraries you are using, and even if there is risk (as pointed out by Peter) to removing unused stuff, there is cost in carrying any kind of excess baggage, and you shouldn't just keep accumulating. If you use reflection, then get a handle on what you are using it for, and systematically get rid of what you don't need. There are benefits to a leaner code-base that you understand better.
Java only loads class as they are used. Removing classes can only cause you problems and won't help you at runtime. 36 MB of code isn't that much given only a portion of it will be loaded. How much memory do you have? Most PC have at least 2000 MB these days If you are downloading your applet or Java WebStart application over a slow link I would imagine you are using pack200 (to make the jars smaller) and have included the minimum of libraries already.