Monday, June 18, 2007

Find java class files in JAR

Typically in a development environment of a big J2EE product, you often cross the step of including the right jars in your library path to get your product compile/run/debug. With lot of jars lying in you lib folder, you face the daunting task of including the needed few.

OR

In case if you want to find from which jar a particular class gets picked up, you face the same daunting task of opening the various jars and looking out for a particular class file packaged inside it.

To get rid of this one, I came up with a java program that takes a path and class name and spits out the jars which contains the class. The usage of FindClass is simple

java FindClass C:\j2ee\product\lib MyClass

FindClass iterates through the folder (and subsequent subfolders) to get the list of available jars and list out the jars, which contains the specified class.

I used JarFile and JarEntry to read a jar file. Rest is all simple File operations.
If you love to use this util class, drop a comment.

4 comments:

Anonymous said...

really, nice!!!

Anonymous said...

where can I find your FindClass code or class file? I would like to use it...

Thanks!
Nick

Anonymous said...

Hi Kumar,
you did a nice work can i have your FindClass file. Where i can find it?
thanks,
Fakhar

Anonymous said...

looks a great app ..
can you help me get it ?