Monday, February 18, 2008

how to find what jar contain a particular class?

Using the Unix bash shell:

if your current directory contains all the jar to scan, and the class you are looking for contains a substring like some.package.MyClass:


for i in `ls *.jar`;
do echo $i;
jar -tvf $i | grep some.package.MyClass;
done;


Your jars can be in different subdirectories, at any level, under the current directory. Then you can use:


for i in `find . -name | egrep ".*\.jar$"`;
do echo $i; jar -tvf $i | grep some.package.MyClass;
done;


The result is the list of all the jars, and if a particular jar contains a class that maatches the string you specified (some.package.MyClass), then the complete name of such classe is prompted after the jar.


Enjoy

2 comments:

jothir said...

It should be jar tvf $i followed by grep command to get this working.

Tonino Lucca said...

Thanks, you are right, somehow I made mistakes in editing.
Now it's correct.