Tuesday, 19 May 2009

JARSearch

This is just a quick post to share a Windows utility (cmd script) for finding Java resources in JAR files located under a given location. This can be very useful in helping to solve ClassNotFound errors by finding out which JAR file should be on the classpath.

This utility looks for JAR files recursively under the given path hopefully simplifying the search process.

The command syntax for the utility is:

jarsearch search_term [search_base]

Where:
  • search_term is a string representing the resource to find and
  • search_base is the path which will be recursively searched for JAR files

This utility uses the JAR command and therefore understands Java packages as directories rather than true dot notation package names. Therefore referencing a package requires using the forward-slash '/' character. For example the following would look for the String class in the java.lang package in ALL JAR files located on drive C:

D:\> jarsearch java/lang/String C:\

And as the search term is just a substring of the filename contained in the JAR it is possible to search for a given package only.

The jarsearch utility is available at:

http://sites.google.com/site/weblogically/files/jarsearch.zip