Search classes in jar file

by admin on May 15, 2013

We do not need to download special tool to search for classes in jar files.  This post explains how to do that without the use of any additional tool.

You need to have java sdk installed on your machine to use this tip. If you are a java developer, you might already have it on your computer.

Search for a class in all the jar files

You can use the below command to search for a class name in all the available jars in the current folder and the subfolders.

 forfiles /S /M *.jar /C "cmd /c jar -tvf @file | findstr /C:"classname" && echo @path"

Example: Search for Logger.class

C:\>forfiles /S /M *.jar /C "cmd /c jar -tvf @file | findstr /C:"Logger.class" && echo @file"
2567 Thu Sep 14 02:03:58 IST 2006 org/apache/log4j/Logger.class
  885 Thu Sep 14 02:04:00 IST 2006 org/apache/log4j/spi/RootLogger.class
  687 Wed Apr 13 10:48:08 IST 2011 org/quartz/core/ErrorLogger.class
 3267 Sat May 08 12:40:52 IST 2010 org/slf4j/helpers/NOPLogger.class
 1375 Sat May 08 12:40:50 IST 2010 org/slf4j/Logger.class
  455 Sat May 08 12:40:50 IST 2010 org/slf4j/spi/LocationAwareLogger.class

If  ‘jar’ command generates error, you may need to add the java binary files folder to PATH environment variable. Otherwise, you can specify the full path of ‘jar.exe’ while running jar command. You can find this file in  C:\Program Files\java\jdk*\bin (or) C:\Program Files(x86)\java\jdk*\bin

List the classes in a jar file

jar -tvf jarfile | findstr /C:".class"

Find all the jar files in a folder

To list all the jar files in the current folder and all its subfolders, we can use the below command.

dir /S /b *.jar

{ 3 comments… read them below or add one }

Tal February 5, 2014 at 1:49 pm

Great one !
Saved me a lot of work :)



Pasinski March 11, 2014 at 4:12 pm

Thanks a lot, worked like a charm


Sander August 5, 2014 at 7:16 am

Very nice, exactly what I was searching for. Thanks!


Leave a Comment

Previous post:

Next post: