Tuesday, March 6, 2012

Class Finder

A simple utility to find a particular class name in a directory containing jar, war, and ear files. The application recursively decends into the directory looking for files that end in ".jar", ".war", and ".ear" (case insensitive which is not really the standard). Additionally, the program finds any normal files that end in .class also.
Why did I write this? Because I find that when I'm looking for a particular class to compile with I never seem to know which jar file it is in. This utility simplifies that task. It is basically like a Unix "find" command piped to the "jar" command that would "grep" for the class name. Cross-platform issues made it easier to put this into a small java application rather than have to install Cygwin on every Windows box I use.

Downloads

ClassFinder can be downloaded from:
These files contain a precompiled jar file along with all of the source code and an ant build file.

Usage

A sample command line might look like (should be all on one line):
java -classpath lib/classfinder.jar com.xigole.util.ClassFinder -d some/directory/name -c SomeClassName
or
java -jar lib/classfinder.jar -d some/directory/name -c SomeClassName
The command line arguments are:
  • -d specifies the directory name to use. This must be a directory. This is a required argument.
  • -c specifies the class name to look for in the jar files. The search is case insensitive unless you specify the -p option. This is a required argument. Note that this argument can be a class name like MyClassName in which case ClassFinder will look for the provided name regardless of the package. Alternately, you can specify a package declaration like com.xigole.MyClassName. Either way ClassFinder is simply looking for a pattern that looks like the given string. Regular expressions are not supported.
  • -p pay attention to the class name case. This makes it easier to find something like "Log" when many classes may be in the "logging" package
  • -v an optional argument that verbosely prints out each file that is being searched.

Important!

ClassFinder requires a 1.4 and above JDK.

Eclipse/RSA/RAD Shortcuts

Open Resource (ctrl+shift+r)
This shortcut allows to open any file in your workspace by only typing the first letters of a file name or a mask, like applic*.xml. The only drawback of this shortcut is that it is not available in all perspectives. To enable this: Right click on the toolbar, select Customise Perspective and make sure 'Open Resource' is checked.

Open Type (ctrl+shift+t)
This shortcut allows to browse the workbench for a type to open in an editor or type hierarchy.