Finding which JAR contains a class

I often want to search through a large number of JAR files looking for a particular class, and every time I do this I wish I had some utility to make it easier.  So I finally made one:

#!/bin/sh

TARGET="$1"

for i in `find . -name "*jar"`
do
  jar tvf $i | grep $TARGET > /dev/null
  if [ $? == 0 ]
  then
    echo "$TARGET is in $i"
  fi
done

Update: My colleague Chris Johnson just posted a better version of this, with some caching over at the Fusion Security Blog.

About Mark Nelson

Mark Nelson is an Architect in the Enterprise Cloud-Native Java Team at Oracle. Mark works mainly on making Java (traditional and microservices) easy to use in Kubernetes and the CNCF ecosystem. Before joining this team, Mark worked on Wercker, WebLogic and was a senior member of the A-Team since 2010, and worked in Sales Consulting at Oracle since 2006 and various roles at IBM since 1994.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

2 Responses to Finding which JAR contains a class

  1. Pingback: Finding which JAR contains a class

  2. Pingback: Finding which JAR contains a class – again! | RedStack

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s