How to search for jar file

I am pretty sure that every java developer were in the situation when he was searching for a java archive file having fully qualified class name.
Fully qualified name is enough info to get this kind of issue resolved. You can either take advantage of sites like http://www.findjar.com/ or features of IDE – search for class. Those approaches works well when missing class is from open source or at least from publicly available jar libraries. If the jar is already in your project but just missing item on the classpath – then the second case is applicable. But then there is vast amount of cases when you are searching for a library from vendor specific product which consists of huge amount of jar files. One way to find a class is to import all those libs to the IDE and then look up for a required class. This approach is a bit awkward. More straightforward approach is to search through product’s filesystem directly. One handy bash script follows – in this case searching for com.oracle.pitchfork.interfaces:

for i in 'find ./  -name "*.jar"'
do
result='$JAVA_HOME/bin/jar -tvf $i'
echo $result | grep -i com.oracle.pitchfork.interfaces >dev/null
if[$? == 0]; then
echo $i;
fi
done

Run this bash from the product’s root folder – all jars containing required class will be listed.

Advertisements

One thought on “How to search for jar file

  1. Good idea. But it doesn’t work for me 😉 I have to made some syntax corrections. I guess that this should work better:

    for i in `find ./ -name “*.jar”`; do result=`$JAVA_HOME/bin/jar -tvf $i`; echo $result | grep javax.xml.bind > /dev/null; if [ $? == 0 ]; then echo $i; fi; done

    (Check for ` instead of ‘, space after if, missing leading slash at dev/null and so on)

    But once more: nice post! 🙂 Thanks

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s