I\'m in need of creating the minimal jar of utils library for use in Android. I\'m using some methods from apache commons libraries (such as IOUtils
, Stri
In general it is not possible to automatically select all classes that are used by an application. Just think about what we can do with Class.forName(String name)
or if we use a dependency injection container and declare types in external configuration files.
I guess if you use Eclipse to JAR the project it gives some options to do that while JARing :) Maybe it will be useful.
Also you can collect your used library classes under a custom library and include this user created library in the project.
The maven plugin you can't remember is probably Apache Maven Shade Plugin, there is minimizeJar
option. As Andreas_D noticed, this won't include classes, loaded with Class.forName
, so you will need to implicity say in configuration, that you need them. Here is how i made maven to include jdbc driver in my single jar:
<filter>
<artifact>net.sourceforge.jtds:jtds</artifact>
<includes>
<include>**</include>
</includes>
</filter>
Excuse me, maybe i not clearly understood question. Obfuscator tool (i.e. ProGuard) could do that, isn't it? It packs several JARs into one and strips unused classes. If you don't need obfuscation/optimization (to prevent unwanted side-effects) then you could disable them, leaving "shrink" phase enabled.