Thursday, November 16, 2017

Script to find the jar file(s) containing the given Java classname

This is very handy when you have compiling error for missing Jar file.
The classname used in your Java file cannot be resolved without the Jar file.
Once you find the Jar file containing information about your classname, you can include it in your Java classpath to resolve the compiling error.


Copy the code below and save it as findJar.sh file.

echo ./findJar.sh dir  classname
echo example: ./findJar.sh .  HBase
find $1 -name "*.jar" | while read JAR; do jar tvf $JAR | grep $2 && echo $JAR ; done



$1 will contain the directory where you want to start the search. It is important that you start with a directory that you know for sure will contain jar files.
$2 is the classname that you want to find in the Jar files. The output may contain more than one Jar files. Pick the one that is relevant to your Java project.

www.findjar.com