views:

412

answers:

4

Is there a tool to detect unneeded jar-files?

For instance say that I have myapp.jar, which I can launch with a classpath containing hibernate.jar, junit.jar and easymock.jar. But actually it will work fine using only hibernate.jar, since the code that calls junit.jar is not reachable.

I realize that reflection might complicate things, but I could live with a tool that ignored reflection. Except for that it seems like a relatively simple problem to solve.

If there is no such tool, what is best practices for deciding which dependencies are needed? It seems to be that it must be a common problem.

+2  A: 

This is not possible in a system that might use reflection.

That said, a static analysis tool could do a pretty good job if you don't use ANY reflection.

Bill K
+2  A: 

Have you taken a look at Dependency Finder?

http://depfind.sourceforge.net/

A handy list of most of the other available Java dependency tools is also available on that site.

shadit
+1  A: 

I have used

http://code.google.com/p/jarjar/

and found it to be pretty good.

Also, you will find out if you have broken any reflection easily if you have a good set of unit/acceptance tests :).

triggerNZ
A: 

Something to add to Bill K's reply: you might not use reflection at all, but the JARs you are using might. I remember encountering something like that with xalan & xerces, where a ClassNotFoundException has been thrown at runtime.

rassie