Posted by tball
on September 3, 2005 at 1:24 PM PDT
Here is a simple tool for finding which jar file holds a Java class.
I'm a big fan of the Unix
find utility for managing large projects. One task that's difficult to do with it, however, is finding which jar file contains a Java class -- you can't use search commands like
grep because it will match on any class that references your target, not just the defining class itself. There are several utilities that do this on the web, but most are big GUI-based tools which seem like overkill for what should be a small job.
So a while back I wrote a simple command-line utility called JFind, which is now in the NetBeans repository here
. It's a single, simple class, which relies on the
packages to do the heavy lifting. Just specify the class or package you want to find and a directory to start your search, and it will report the jar file or path that defines it.
For example, to find which jar provides
NetBeans distribution, run:
java -jar jfind.jar org.openide.ErrorManager dist
To find which jar provides the
package in the JDK:
java -jar jfind.jar -p javax.crypto JDK-directory
One could write a more complex, Swiss-army-knife-like utility (like the Unix find utility), but sometimes short and sweet works best.