views:

789

answers:

5

I have a Java project that currently has a lot of JARs in its libraries directory, which are all included in the resulting package when building. I know, however, that some of these libs are never referenced in the project.

Is there a tool that can search for libs that are not referenced within the project? I guess there must be something in that sense.

BTW, an Eclipse plugin would be awesome.

EDIT: I chose to go with ClassDep because it was the only suggestion that worked. However, I'm having some trouble with it: please check this question

+1  A: 
VonC
I must hang out here too much... When I saw an Eclipse screenshot, I immediately thought "VonC!"
Michael Myers
TssTss... and yet another entry to add to the "You know you’ve been browsing Stack Overflow too much when?" question ( http://stackoverflow.com/questions/247342 ) ;)
VonC
André Neves
Checking right now
VonC
VonC
probably a mirror issue. Try my link or try to switch between different mirrors.
VonC
Your link didn't work here either, plus I can't get to see a list of mirrors to choose from (just autodetect).
André Neves
Strange. Since I can download it (behind a corporate HTTP proxy), I suppose you may have a problem with your Internet access configuration. The file is certainly available.
VonC
I asked a bunch of friends from different places in town to test the link and it still fails to work. Certainly not a problem here, and I'd really like to test the app before leaving for tomorrow. Any chances of uploading the bins somewhere? :) <- nice smile
André Neves
Didn't work in my Eclipse environment.
André Neves
A: 

Not an eclipse plugin, but I believe the "shrinking" functionality of ProGuard is exactly what you're looking for.

Michael Borgwardt
I don't think so: proguard can remove unused classes from your input jars but does not remove library jars from a project
Maurice Perry
+2  A: 

ClassDep (from Sun, in the Jini development kit) will do this for you.

Brian Agnew
It seems great, but looks like it isn't trivial to use. I'm posting another question regarding it.
André Neves
Hi, Brian. If you could, please check out http://stackoverflow.com/questions/745574/classpath-problems-with-jini-classdep-javas-dependency-finder
André Neves
ClassDep link given above is now pointing to some Apache River project which has no clue as to how to use it. Anyone got suggestions?
Calm Storm
+4  A: 

Beware of the case that a class is loaded via Class.forName() and not specified as a dependency in the manifest file (there is a Depends-On: attribute that is for that, but many people don't specify it, which breaks tools like this, the bane of my existence when I worked on such a tool).

TofuBeer
hello Halting problem!
matt b
@Matt Not 100% sure what you mean... can you elaborate?
TofuBeer
A: 

You also can't tell if JARs that you don't import are required dependencies of dependencies. For example, if you use Spring it comes with its own dependencies, even if you don't import or call those classes in your code. I'm ignorant of ProGuard - does it check for those cases?

duffymo
A proper dependency tracker will do that (I wrote one back in 1998/9 that did that).
TofuBeer