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?
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.
Compressing files in JAR format: We use the JarArchiveOutputStream to compress files and/or directories into JAR format. We can add entries in the archive using the JarArchiveOutputStream. putArchiveEntry method and pass in a JarArchiveEntry as an argument containing the file and filename respectively..
You can use the JAR file editor to view or edit JAR file information that is stored in a data development project. If you make changes to JAR file information using the editor, you must deploy the JAR file to the database server again to apply the changes to the server version of the JAR file.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With