Did you know there’s a tool that can help you search through JAR files to find Java classes or packages? I’ve been using it for years and I am often surprised that so few Java developers have it in their toolbox. Of course, it’s very handy for resolving those pesky NoClassDefFoundError and ClassNotFoundExceptions, but my favorite use case is to find the location of a class and JAR file on my hard-drive so I can decompile it to understand what some vendor’s proprietary code is actually doing behind the scenes. I know vendors frown on this, but whatever; I’ve got a job to do.
The tool is called jarscan and you can read more about it or download it here.
It’s just a little jar file that executes as a command-line program. On my Windows virtual machines, I put the jar file in C:\JarScanner\
If you’d like to find a Java class called “SystemProperty” somewhere in the “C:\IBM\WebSphere\PortalServer” directory. You would execute the following command:
java -jar C:\JarScanner\jarscan.jar -dir c:\IBM\WebSphere\PortalServer -class SystemProperty
That command would then search through every jar file that it can find in the PortalServer directory, including sub-directories. If it finds the specified class file, it reports the location and name of the Jar file containing the class. You can also search for packages, not just class files.
For Help, type the following command:
java -jar C:\JarScanner\jarscan.jar -help
Shout out to Geoff Yaworski for building this handy tool (there’s a PayPal donate link on his site)