Categories: Java

Search classes in jar file

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

List all the jars installed on the system

You can run the below command to list all the jar files available on your computer.

dir c:\  d:\ /S /b | findstr /E /C:".jar"

This command looks for jar files in the system drives C: and D:

Srini

View Comments

Share
Published by
Srini

Recent Posts

Add new user account from command line (CMD)

Adding users from command line is much easier than going through the UI. It saves…

4 years ago

Delete directory from command line [Rmdir]

Do you want to delete a directory from Windows command prompt(CMD)? This post explains how…

4 years ago

TaskKill: Kill process from command line (CMD)

We can kill a process from GUI using Task manager. If you want to do…

4 years ago

Kill Chrome from command line

Chrome is definitely the stable browser compared to other ones and it has been my…

4 years ago

Find windows OS version from command line

Windows has multiple command line utilities that can help find the version of the Windows…

4 years ago

How to check if Windows 32 or 64 bit?

There are multiple ways to check whether a Windows computer is running 32-bit OS or…

7 years ago