Java – optional jar wrapper
I have a small program Jar, which uses a huge library A small part of the jar
Is there a tool to repackage several cans into one so that it can run independently and as small as possible?
Update: size is important
Solution
There are Proguard, ant and Maven plug-ins It removes unused code and optionally obfuscates and compresses it into a jar
Proguard reduces size in two ways
>Only the classes actually used are stored in the final jar. > Long names, such as all long package names and class names, are renamed to shorter names, saving considerable space
Determining whether to use classes in Java is tricky Static code analysis can get you so far, but you need to access some careful code through reflection, because the tool may not be able to detect it It handles class Forname ("xyzfoo"), but it is more complex. You need to add it to the configuration file of the included classes. It is possible for the class loader to generate a list of classes used at runtime, so this is not necessarily arduous
You may also want to study the pack 200 compression scheme, because it can also significantly reduce the size of jars