Resolver dependencias de jar automáticamente

A project was using various libraries. E.g. a.jar, b.jar,c.jar,d.jar etc.
Some of the jars have been refactored and now is ab.jar y cd.jar etc.
What I need is an automatic way to find which jars in my installation are now obsolete and I can delete them.
¿Es esto posible?

preguntado el 28 de agosto de 12 a las 10:08

use some kind of dependency management system -

@Jason Sperske, care to post your comment as an answer? -

2 Respuestas

Entonces con LooseJar you can detect unused Jar files by adding:


to your java command when you invoke form the command line (or as a VM option in Eclipse). I guess this isn't technically automatic because lines of code that dynamically load classes at runtime will need to be invoked in order for LooseJar to know that the class and therefor the jar is needed. A good method might be to invoke your unit tests with this java agent (assuming your unit tests have good code coverage)

Respondido 28 ago 12, 10:08

The best way is to use maven. If dependencies are defined in maven you can just run mvn dependency:tree to retrieve needed information. Please refer to this artículo para más detalles.

If you do not use maven you probably have to use tools like depender. But be careful: such tools cannot really retrieve todos dependencies. It is impossible to retrieve dependency on dynamically loaded class or API being called by reflection using static analysis only. Full solution may be achieved only if you are running your application, test it with all possible scenarios and check what classes are loaded by class loader. If you have 100% test coverage you can run your application using option -verbose:class and then run all unit tests against your application. You will get a list of all loaded classes. Now put this list to file and write shell script that analyses the classes list and transforms it to jars list.

Respondido 28 ago 12, 10:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.