Take the 2-minute tour ×

This must be a very basic question for Java developers, but what is the best way to find the appropriate jar file given a class name?

For example, given "com.ibm.websphere.security.auth.WSSubject", how do you track down the appropriate jar file? ("google" is not the answer I'm looking for!)

The java docs do not give any hint of the jar file, and obviously the names of the jar files themselves offer no clue.

There must be a 'search local jars', or some sort of 'auto-resolve dependencies', trick in the java world. Ideally, I'm looking for the 'official' way to do this. I happen to be on a windows machine without cygwin.

share|improve this question
Are you attempting to resolve a dependency? i.e. when you run your code, it cannot find a class, so you are looking to put it on the classpath? –  aperkins Sep 30 '09 at 19:23
Yes, that is exactly what I am trying to do. –  Jeffrey Knight Sep 30 '09 at 19:24
I think you're asking the wrong question. I think the question you mean to ask is something like "I'm trying to develop a thin client application using WAS v6.1. Which jar should I include on my JVM class path to perform authentication (presumably WSSubject)?" Depending on what you're actually trying to do, searching the InfoCenter for "thin client" or "thin client wssubject" is probably what you're looking for. If you provide details, you can probably get the correct jar rather than just guessing based on the answers below. –  bkail Oct 1 '09 at 4:22
This should be tagged Linux/Unix - no use in Windows. –  orbfish Jan 14 at 16:26

16 Answers 16

up vote 51 down vote accepted

Save this as findclass.sh (or whatever), put it on your path and make it executable:

find "$1" -name "*.jar" -exec sh -c 'jar -tf {}|grep -H --label {} '$2'' \;

The first parameter is the directory to search recursively and the second parameter is a regular expression (typically just a simple class name) to search for.

$ findclass.sh . WSSubject

The script relies on the -t option to the jar command (which lists the contents) and greps each table of contents, labelling any matches with the path of the JAR file in which it was found.

share|improve this answer
I'm not sure if you or Dave Costa answered first, but this does the trick and I can use this script going forward. Thanks! –  Jeffrey Knight Oct 1 '09 at 5:11
Dave answered first. His answer is simpler and will run quicker, but I think mine is slightly more flexible as you don't have to specify the fully-qualified class name. –  Dan Dyer Oct 1 '09 at 10:34

There is no "official" Java way to do this AFAIK.

The way I usually hunt for it is to use find and jar to look through all jar files in a given tree.

> find . -name \*.jar -print -exec jar tf {} oracle/sql/BLOB.class \;

If you're on Windows and don't want to install Cygwin, then I suppose you would have to write a batch script to locate the jar files.

share|improve this answer
Note that jar files are zip files, and the filename in the jar effectively map to the package and class. –  TREE Sep 30 '09 at 19:44
I like this more because it doesn't involve grep –  David Mann Mar 12 at 18:09

I have written a program for this: http://code.google.com/p/jar-explorer/ It will also decompile existing byte code to show you interfaces, methods, super classes, will show contents of other resources - text, images, html, etc.

share|improve this answer
Helped me. Thanks. –  Corey Trager Jul 9 '12 at 20:37

If the grep on your system (e.g. Solaris) doesn't have -H and --label as used in Dan Dyer's example, you can use:

find . -name '*.jar' -type f | xargs -i bash -c "jar -tvf {}| tr / . | grep WSSubject && echo {}"
share|improve this answer

To search all jars under the current directory and return the one(s) that contain class a.b.c.D do a:

find . -iname *.jar | while read JARF; do jar tvf $JARF | grep a/b/c/D.class && echo $JARF ; done

It will report all instances of class a.b.c.D (or classes with a similar suffix) and will only print the jars that contain it.

Typical output:

$ find . -iname *.jar | while read JARF; do jar tvf $JARF | grep Log.class && echo $JARF ; done
479 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/Log.class
3714 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/impl/Log4JCategoryLog.class
1963 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/impl/NoOpLog.class
9065 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/impl/SimpleLog.class
share|improve this answer

You could try services like:



  • A maven enterprise repository with a search feature e.g. Nexus (OFC, this would only work if the jars you're looking for are indexed i.e. installed in the repository)

PS: Jarhoo has teamed up with Javacio.us to provide 100,000 Java developers with free access to Jarhoo via links integrated with their Google search results. Subscription to Javacio.us is free and open to anyone with a Google account. For more information, please visit the Jarhoo offer page at Javacio.us.

share|improve this answer
- jarhoo costs money - docjar doesn't find "WSSubject" from my example (docjar.com/docs2web/s.jsp?q=WSSubject&t=q&start=0). There must be a 'search local jars' approach typically used by java devs .. ? –  Jeffrey Knight Sep 30 '09 at 19:31
I'm hoping for an offline option. I often find myself dealing with somewhat obscure jar's from 3rd party vendors. –  Jeffrey Knight Sep 30 '09 at 19:33
AFAIK, there is nothing built-in under Windows that can help for this. So, if you exclude cygwin, Googke Desktop may be the best (the less worst?) option. –  Pascal Thivent Sep 30 '09 at 19:53

Printing the list as I go so I can see what I'm checking. Mostly I'm looking in a lib/app directory, but you can substitute a locate for the find.


for jar in $(find some_dir/lib -name "*.jar" ); 
echo -------------$jar-------------------
jar -tf $jar | grep TheNameOfTheClassImLookingFor
share|improve this answer

In Windows, run cmd.exe and type:

  for %i in (*.jar) do @jar tvf %i | find "/com/company/MyClass.class"

The jars would have to be in the current directory. For also has a /R option which takes a directory and lets you search recursively.

If Jar.exe isn't in your path, you can do something like @C:\jdk\bin\jar.exe.

share|improve this answer

Try findjar.com. If it's in the public domain, you should get it. There's alos mavenjava.com (but that site seems to be down)

share|improve this answer
There is also jarfinder.com. But they both seem to offer rather obsolete versions of jars. In conrast grepcode.com stays current on public code but can be used only as a hint on where to look and what the actual jar name is. –  Vadzim Dec 19 '11 at 17:20

Given your comment on attempting to handle dependencies, what I would do is focus on which libraries you are using. Knowing this, you will know what jars have to be on the classpath, and you can pay attention to that. There are also dependency management builders (Maven and Ant being two popular ones) that can package up projects with their dependencies inside. However, in the end, it is up to the developer to know which dependencies they have, and to pay attention to the requirements for those dependencies. This is one reason why using an IDE like Eclipse, and build tools like Maven or Ant are so nice in large projects, as when you have 20 dependencies for a project, that can become pretty unmanageable.

share|improve this answer

I use jarscan. It is an executable jar file that can recursively search an entire folder structure for jars that contain the class that you are looking for. It searches by class name, package name or regex.

share|improve this answer
Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead. –  Kev May 10 '12 at 1:14
for usage with windows, I've put jarscan.jar into PATH together with jarscan.bat that contains java -jar %~dp0jarscan.jar -class %1 %2 %3 %4 %5 %6 %7 %8 %9 - then it can be used just with "jarscan ServletRequest" –  eis Sep 13 '12 at 12:58

In windows powershell you can use this command. It list all the JAR files it encounters, but it has an extra line that's very easy to spot where it also finds your class.

Get-ChildItem -recurse -Filter *.jar | Foreach {echo $_.fullname; c:\somepath\JDK\BIN\jar tvf $_.fullname | Select-String -pattern "Cabbages.class"}
share|improve this answer

There is also this web site that seems to be usefull. http://www.findjar.com/

share|improve this answer

locate .jar | xargs grep com.ibm.websphere.security.auth.WSSubject

share|improve this answer
Good answer for *nix, but it doesn't help on windows (though judging by his example *nix would be fine). –  C. Ross Sep 30 '09 at 19:28
Fair enough, but what's the standard approach for a java developer on a windows machine that doesn't involve installing cygwin? –  Jeffrey Knight Sep 30 '09 at 19:30
Find in files, *.jar, with the class as the string? (don't actually know if this works, but if grep works, this should) –  TREE Sep 30 '09 at 19:45

I recommend using Maven, Eclipse and m2eclipse.

Step 1 - add specific import

alt text

Step 2 - find and download (automatically) desired jar

alt text

share|improve this answer

if you are still searching for WSSubject, then jar is wssec.jar. WSSecurityException class inside sas.jar

share|improve this answer

Your Answer


