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
C:\jars\lib\log4j-1.2.14.jar"
  687 Wed Apr 13 10:48:08 IST 2011 org/quartz/core/ErrorLogger.class
C:\jars\lib\quartz-all-1.8.5.jar"
 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
C:\jars\lib\slf4j-api-1.6.0.jar"

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

{ 2 comments… read them below or add one }

Tal February 5, 2014 at 1:49 pm

Great one !
Saved me a lot of work :)

Thanks,
Tal

Reply

Pasinski March 11, 2014 at 4:12 pm

Thanks a lot, worked like a charm

Reply

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: