Sunday, January 24, 2010

Searching classes in a JAR or multiple JARs

It's very common in the world of Java that you are developing an application using some libraries or open source frameworks or some 3rd party jar and while executing your application/program all of a sudden you get NoClassDefFoundError. This is because the runtime dependency of one of the jars you are using is not in the classpath of your application. Next step you do is start wondering where you will find that particular class. Probably you already know which jar to include and probably you have no clue where to look for that particular class. In the later case (almost all the time with me :-)) you end up hitting the icon of your favorite browser and start googling. In 99% cases you will get the name of the jar where to look for the class but in some cases, where the missing class is a part of some jar which is very much specific to some internal application or 3rd party library, google will be of little help.

I've been in such a situation many times and there are instances where I have invested (read wasted) significant amount of time just clicking through directories, opening jar files and finding the class am looking for. One fine day I realized that I should have something which does this for me automatically and easily. Result of this thought was a small utility - JAR Reader - which is having a small cute swing UI where I can
  1. Specify which class to find
  2. In which directory to find
  3. Whether to look for the exact match or just part of. This is useful when I'm just looking for a package name or when I just know the name of the class and not sure of package name.

This small handy utility has save a lot of time of mine. It searches for class in all the available jars under one directory and all the sub-directories within the search root directory. I'm sure there are many out there who would be facing same problem and for all those poor souls, I've made this download link available to download the utility. Download it and use it however and when ever you want to use it.

To start the JAR reader utility, just open the command prompt, change the directory where you have copied the jarreader.jar file and execute following command...

java -jar jarreader.jar

with above you should be seeing as swing window as the snapshot above...

@Also See: Online site which can tell you the name of the jar file for a particular class. A nice bookmark to have with you all the time.

Cheers !!!
- Jay
Disclaimer : This is a personal blog and all content represent what I think and it does not advocate/support/advertise any other person/company. I do not earn money or intended to do so with this blog or any of the contents the blog hosts (except the google ads which you see). If I post something here that you find helpful, that's wonderful. Just in case, if I say something stupid, the stupidity is mine, and mine alone and I can not be held for anything if you fall for such stupidity :-). I cannot be held responsible for any kind of damage that may be caused by downloading or viewing the files or information provided herewith. Anybody and everybody can use/refer the contents of this blog at their own will and of course at own risk. There is no need for any kind of approval of the author. Although it would be great if feedback is left for any such usage to the author.