tags:

views:

287

answers:

4

Hi all,

still learning, so be patient :) I've developed a module for a Java project. The module depends on external library (fastutil). the problem is, the fastutil.jar file is a couple of times heavier than the whole project itself (14 MB). I only use a tiny subset of the classes from the library. the module is now finished, and no-one is likely to extend it in future. is there a way I could extract only the relevant class to some fastutil_small.jar so that others don't have to download all this extra weight?

there's probably a simple answer to this, but as I said, I still consider myself a noob.

Thanks a lot

+3  A: 

Obfuscation tools such as ProGuard usually provide a feature to remove unused classes (and even fields and methods) from the jar file. You have to be careful to verify everything still works, 'though, because you might be using reflecton to access classes or methods that ProGuard can't analyze.

You can use only that feature and already get quite some saving

Or you could combine it with other space-saving obfuscation techniques (such as class and method renaming) to save even more space at the cost of harder debugging (your stack traces will become harder to parse).

Joachim Sauer
+1 the first 5 words are exactly of what i was thinking, as i read this question
Markus Lausberg
from proguard instructions:'ProGuard requires the library jars (or wars, ears, zips, or directories) of the input jars to be specified. These are essentially the libraries that you would need for compiling the code. ProGuard uses them to reconstruct the class dependencies that are necessary for proper processing. The library jars themselves always remain unchanged. You should still put them in the class path of your final application.'But reducing the size of library jar files is exactly what I want (or am I using the wrong vocabulary?). What am I missing?
joe_shmoe
@joe: you can easily work around this, by specifying the library via `-injars` and not via `-libraryjars`
Joachim Sauer
in the end i managed to use autojar, but thanks for the help anyways :)
joe_shmoe
Thanks for accepting this answer, but if you used autojar, you should probably have accepted that answer instead ;-)
Joachim Sauer
oh crap. i thought you can accept more than one.
joe_shmoe
A: 

Yeah one crude is to have a backup of your original jar. then remove all unused class files from the jar. and there may be some internal references to other class which you can add as and when it is required. ie while executing it may throw a class not found exception so then you can add that class from the original jar to this jar.

GK
+4  A: 

From the installation instructions of fastutil:

Note that the jar file is huge, due to the large number of classes: if you plan to ship your own jar with some fastutil classes included, you should look at AutoJar (also available at JPackage) to extract automatically the necessary classes.

Thilo
Yes, I did rtfm :) I just didn't quite manage to do anything useful with it yet (noob, remember? :) )
joe_shmoe
well, turns out, all I had to do was try it three times.
joe_shmoe
+1  A: 

As fastutil is LGPL open-source software, you could just copy the relevant source files to your project and drop that jar file. The compiler will then tell you if have all the files you need. Just keep the packages as they are and put a copy of the fastutil license file on top.

Jörn Zaefferer