What Jar File

When working a with a new project, I often find I am searching for the Jar files that fulfill a dependency. Sometimes they come from maven, sometimes from the Fedora RPMS. My approach has been to make a cache of the Jar files in the directories that I care about that contains a map from jar file name to class name:

#!/bin/bash

CACHE_FILE=/tmp/jarcache

echo > $CACHE_FILE

for DIR in /usr/share/java /usr/lib/java
do
    for JAR in `find $DIR -name \*.jar`
    do
        #only do the non-symlinked versions
        if [ -f $JAR ]
        then
            for CLASS_FILE in `jar -tf $JAR | grep \.class`
            do
                CLASS=`echo $CLASS_FILE | sed 's!/!.!g'`
                echo $JAR $CLASS >> $CACHE_FILE
            done
        fi
    done
done

Then call it this way:

grep "org.mozilla.jss.ssl" /tmp/jarcache

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.