Find a class somewhere inside dozens of JAR files?

How would you find a particular class name inside lots of jar files?

(Looking for the actual class name, not the classes that reference it.)


Eclipse can do it, just create a (temporary) project and put your libraries on the projects classpath. Then you can easily find the classes.

Another tool, that comes to my mind, is Java Decompiler. It can open a lot of jars at once and helps to find classes as well.


Use the jar (or unzip -v), grep, and find commands.

For example, the following will list all the class files that match a given name:

for i in *.jar; do jar -tvf "$i" | grep -Hsi ClassName && echo "$i"; done

If you know the entire list of Java archives you want to search, you could place them all in the same directory using (symbolic) links.

Or use find (case sensitively) to find the JAR file that contains a given class name:

find path/to/libs -name '*.jar' -exec grep -Hls ClassName {} \;

For example, to find the name of the archive containing IdentityHashingStrategy:

$ find . -name "*.jar" -exec grep -Hsli IdentityHashingStrategy {} \;

If the JAR could be anywhere in the system and the locate command is available:

for i in $(locate "*.jar");
  do echo $i; jar -tvf $i | grep -Hsi ClassName;


Open a command prompt, change to the directory (or ancestor directory) containing the JAR files, then:

for /R %G in (*.jar) do @jar -tvf "%G" | find "ClassName" > NUL && echo %G

Here's how it works:

  1. for /R %G in (*.jar) do - loop over all JAR files, recursively traversing directories; store the file name in %G.
  2. @jar -tvf "%G" | - run the Java Archive command to list all file names within the given archive, and write the results to standard output; the @ symbol suppresses printing the command's invocation.
  3. find "ClassName" > NUL - search standard input, piped from the output of the jar command, for the given class name; this will set ERRORLEVEL to 1 iff there's a match (otherwise 0).
  4. && echo %G - iff ERRORLEVEL is non-zero, write the Java archive file name to standard output (the console).


Use a search engine that scans JAR files.

some time ago, I wrote a program just for that:

grep -l "classname" *.jar

gives you the name of the jar

find . -name "*.jar" -exec jar -t -f {} \; | grep  "classname"

gives you the package of the class



for jar in $(find $* -type f -name "*.jar")
  match=`jar -tvf $jar | grep $pattern`
  if [ ! -z "$match" ]
    echo "Found in: $jar"
    echo "$match"

I didn't know of a utility to do it when I came across this problem, so I wrote the following:

public class Main {

    private static String CLASS_FILE_TO_FIND =
    private static List<String> foundIn = new LinkedList<String>();

     * @param args the first argument is the path of the file to search in. The second may be the
     *        class file to find.
    public static void main(String[] args) {
        if (!CLASS_FILE_TO_FIND.endsWith(".class")) {
            CLASS_FILE_TO_FIND = CLASS_FILE_TO_FIND.replace('.', '/') + ".class";
        File start = new File(args[0]);
        if (args.length > 1) {
            CLASS_FILE_TO_FIND = args[1];
        for (String s : foundIn) {

    private static void search(File start) {
        try {
            final FileFilter filter = new FileFilter() {

                public boolean accept(File pathname) {
                    return pathname.getName().endsWith(".jar") || pathname.isDirectory();
            for (File f : start.listFiles(filter)) {
                if (f.isDirectory()) {
                } else {
        } catch (Exception e) {
            System.err.println("Error at: " + start.getPath() + " " + e.getMessage());

    private static void searchJar(File f) {
        try {
            System.out.println("Searching: " + f.getPath());
            JarFile jar = new JarFile(f);
            ZipEntry e = jar.getEntry(CLASS_FILE_TO_FIND);
            if (e == null) {
                e = jar.getJarEntry(CLASS_FILE_TO_FIND);
                if (e != null) {
            } else {
        } catch (IOException e) {


To locate jars that match a given string:

find . -name \*.jar -exec grep -l YOUR_CLASSNAME {} \;

There are also two different utilities called both "JarScan" that do exactly what you are asking for: JarScan ( and JarScan (

user1207523's script works fine for me. Here is a variant that searches for jar files recusively using find instead of simple expansion;

for i in `find . -name '*.jar'`; do jar -tf "$i" | grep $1 | xargs -I{} echo -e "$i : {}" ; done

I've always used this on Windows and its worked exceptionally well.

findstr /s /m /c:"package/classname" *.jar, where

findstr.exe comes standard with Windows and the params:

  • /s = recursively
  • /m = print only the filename if there is a match
  • /c = literal string (in this case your package name + class names separated by '/')

Hope this helps someone.

A bash script solution using unzip (zipinfo). Tested on Ubuntu 12.


# ./ "/a/Starting/Path" "aClassName"

jars=( $( find -P "$1" -type f -name "*.jar" ) )

for jar in ${jars[*]}
        classes=( $( zipinfo -1 ${jar} | awk -F '/' '{print $NF}' | grep .class | awk -F '.' '{print $1}' ) )
        if [ ${#classes[*]} -ge 0 ]; then
            for class in ${classes[*]}
                    if [ ${class} == "$2" ]; then
                        echo "Found in ${jar}"

I found this new way

bash $ ls -1  | xargs -i -t jar -tvf '{}'| grep Abstract
jar -tvf activation-1.1.jar
jar -tvf antisamy-1.4.3.jar
  2263 Thu Jan 13 21:38:10 IST 2011 org/owasp/validator/html/scan/AbstractAntiSamyScanner.class

So this lists the jar and the class if found, if you want you can give ls -1 *.jar or input to xargs with find command HTH Someone.

Check JBoss Tattletale; although I've never used it personally, this seems to be the tool you need.

Just use FindClassInJars util, it's a simple swing program, but useful. You can check source code or download jar file at

Not sure why scripts here have never really worked for me. This works:

for i in *.jar; do jar -tf "$i" | grep $1 | xargs -I{} echo -e "$i : {}" ; done

To search all jar files in a given directory for a particular class, you can do this:

ls *.jar | xargs grep -F MyClass

or, even simpler,

grep -F MyClass *.jar

Output looks like this:

Binary file foo.jar matches

It's very fast because the -F option means search for Fixed string, so it doesn't load the the regex engine for each grep invocation. If you need to, you can always omit the -F option and use regexes.

Script to find jar file:

IFS=$(echo -en "\n\b") # Set the field separator newline

for f in `find ${1} -iname *.jar`; do
  jar -tf ${f}| grep --color $2
  if [ $? == 0 ]; then
    echo -n "Match found: "
    echo -e "${f}\n"
unset IFS

Usage: ./ < top-level directory containing jar files > < Class name to find>

This is similar to most answers given here. But it only outputs the file name, if grep finds something. If you want to suppress grep output you may redirect that to /dev/null but I prefer seeing the output of grep as well so that I can use partial class names and figure out the correct one from a list of output shown.

The class name can be both simple class name Like "String" or fully qualified name like "java.lang.String"

To add yet another tool... this is a very simple and useful tool for windows. A simple exe file you click on, give it a directory to search in, a class name and it will find the jar file that contains that class. Yes, it's recursive.

You can find a class in a directory full of jars with a bit of shell:

Looking for class "FooBar":

for jarfile in $(find $LIBDIR -name "*.jar"); do
   echo "--------$jarfile---------------"
   jar -tvf $jarfile | grep FooBar

One thing to add to all of the above: if you don't have the jar executable available (it comes with the JDK but not with the JRE), you can use unzip (or WinZip, or whatever) to accomplish the same thing.

shameless self promotion, but you can try a utility I wrote :

It supports most common archive/compressed files (jar, zip, tar, tar.gz etc) and unlike many other jar/zip finders, supports nested zip files (zip within zip, jar within jar etc) till unlimited depth.

A bit late to the party, but nevertheless...

I've been using JarBrowser to find in which jar a particular class is present. It's got an easy to use GUI which allows you to browse through the contents of all the jars in the selected path.

Following script will help you out

for file in *.jar
  # do something on "$file"
  echo "$file"
  /usr/local/jdk/bin/jar -tvf "$file" | grep '$CLASSNAME'

This one works well in MinGW ( windows bash environment ) ~ gitbash

Put this function into your .bashrc file in your HOME directory:

# this function helps you to find a jar file for the class
function find_jar_of_class() {
  jars=( $( find -type f -name "*.jar" ) )
  for i in ${jars[*]} ; do 
    if [ ! -z "$(jar -tvf "$i" | grep -Hsi $1)" ] ; then
      echo "$i"

Grepj is a command line utility to search for classes within jar files. I am the author of the utility.

You can run the utility like grepj package.Class my1.jar my2.war my3.ear

Multiple jar, ear, war files can be provided. For advanced usage use find to provide a list of jars to be searched.

Check this Plugin for eclipse which can do the job you are looking for.

Under a Linux environment you could do the following :

$ find <base_dir> -name *.jar -print0 | xargs -0 -l jar tf | grep <name>

Where name is the name of the class file that you are looking inside the jars distributed across the hierarchy of directories rooted at the base_dir.

You can use locate and grep:

locate jar | xargs grep 'my.class'

Make sure you run updatedb before using locate.

Use this.. you can find any file in classpath.. guaranteed..


public class FileFinder {

    public static void main(String[] args) throws Exception {

        String file = <your file name>;

        ClassLoader cl = ClassLoader.getSystemClassLoader();

        URL[] urls = ((URLClassLoader)cl).getURLs();

        for(URL url: urls){
            listFiles(file, url);

    private static void listFiles(String file, URL url) throws Exception{
        ZipInputStream zip = new ZipInputStream(url.openStream());
          while(true) {
            ZipEntry e = zip.getNextEntry();
            if (e == null)
            String name = e.getName();
            if (name.endsWith(file)) {
                System.out.println(url.toString() + " -> " + name);


In eclipse you can use the old but still usable plugin jarsearch

Need Your Help

International phone number max and min?

standards phone-number

What is the max and min digits for an international telephone number?

REST API DESIGN - Getting a resource through REST with different parameters but same url pattern

rest url jax-rs url-scheme url-pattern

I have a question related to REST url design. I found some relevant posts here: Different RESTful representations of the same resource and here: RESTful url to GET resource by different fields but ...