In our application through the process of developing a lot of JAR files has been collected. How can I filter out those, which are not used by application anymore? On some easy way?
Write a script which removes them one by one from your build path, compiles the project and checks for build errors. The script would assemble a list of unused jars. Should be easy to write in bash/python.
This solution cannot track runtime dependencies based on reflection (see my comment below).
if youre using maven, there's a mojo for that : mvn dependency:analyze if not, i dont know of any easy way. the hard way would involve bytecode analysis of all the compiled classes of your project to inspect imports ...
Maybe you could write your own ClassLoader, inheriting from java.lang.ClassLoader, that logs the paths of loaded classes? That still doesn't solve the problem of ensuring full coverage of all classes loaded during all possible code paths, though
If you are sure your you can exercise your application so that it uses all it's jars, you can create a simple perl script:
while (<>) {
$l{$1}++ if m/\s+from\s+(.+\.jar)/;
}
for $l (keys(%l)) {
print "$l\n";
}
(lets name it list_jars.pl) and feed it the output of a verbose run:
java -verbose -jar YOUR_APP.jar | perl list_jars.pl
which should list all sources of classes loaded.