Resolver dependencias de jar automáticamente
Frecuentes
Visto 1,584 veces
2 Respuestas
2
Entonces con LooseJar you can detect unused Jar files by adding:
-javaagent:loosejar.jar
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
2
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 java jar or haz tu propia pregunta.
code.google.com/p/loosejar? - Jason Sperske
use some kind of dependency management system - Umesh Awasthi
@Jason Sperske, care to post your comment as an answer? - aviad