I want to search for a particular class file among many jar files without giving the location of each jar file.
Is this possible with a simple command?
I tried t
Most of the solutions are directly using grep command to find the class. However, it would not give you the package name of the class. Also if the jar is compressed, grep will not work.
This solution is using jar command to list the contents of the file and grep the class you are looking for.
It will print out the class with package name and also the jar file name.
find . -type f -name '*.jar' -print0 | xargs -0 -I '{}' sh -c 'jar tf {} | grep Hello.class && echo {}'
You can also search with your package name like below:
find . -type f -name '*.jar' -print0 | xargs -0 -I '{}' sh -c 'jar tf {} | grep com/mypackage/Hello.class && echo {}'