<p>Is there a tool to detect unneeded jar-files?</p>

<p>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.</p>

<p>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.</p>

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

[{'answer_id': 76338, 'author': 'Bill K', 'author_id': 12943, 'author_profile': 'https://Stackoverflow.com/users/12943', 'pm_score': 2, 'selected': False, 'text': "<p>This is not possible in a system that might use reflection.</p>\n\n<p>That said, a static analysis tool could do a pretty good job if you don't use ANY reflection.</p>\n"}, {'answer_id': 77021, 'author': 'shadit', 'author_id': 9925, 'author_profile': 'https://Stackoverflow.com/users/9925', 'pm_score': 2, 'selected': False, 'text': '<p>Have you taken a look at Dependency Finder?</p>\n\n<p><a href="http://depfind.sourceforge.net/" rel="nofollow noreferrer">http://depfind.sourceforge.net/</a></p>\n\n<p>A handy list of most of the other available Java dependency tools is also available on that site.</p>\n'}, {'answer_id': 77066, 'author': 'triggerNZ', 'author_id': 13822, 'author_profile': 'https://Stackoverflow.com/users/13822', 'pm_score': 1, 'selected': False, 'text': '<p>I have used </p>\n\n<p><a href="http://code.google.com/p/jarjar/" rel="nofollow noreferrer">http://code.google.com/p/jarjar/</a> </p>\n\n<p>and found it to be pretty good.</p>\n\n<p>Also, you will find out if you have broken any reflection easily if you have a good set of unit/acceptance tests :).</p>\n'}, {'answer_id': 77081, 'author': 'Nikolai Prokoschenko', 'author_id': 6460, 'author_profile': 'https://Stackoverflow.com/users/6460', 'pm_score': 0, 'selected': False, 'text': "<p>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 &amp; xerces, where a ClassNotFoundException has been thrown at runtime.</p>\n"}]
['https://Stackoverflow.com/questions/76291', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5542/']