This must be a very basic question for Java developers, but what is the best way to find the appropriate jar file given a class name?
For example, given "com.ibm.websphere.security.auth.WSSubject", how do you track down the appropriate jar file? ("google" is not the answer I'm looking for!)
The java docs do not give any hint of the jar file, and obviously the names of the jar files themselves offer no clue.
There must be a 'search local jars', or some sort of 'auto-resolve dependencies', trick in the java world. Ideally, I'm looking for the 'official' way to do this. I happen to be on a windows machine without cygwin.
this is a very simple and useful tool for windows. A simple exe file you click on, give it a directory to search in, a class name and it will find the jar file that contains that class. Yes, it's recursive.
The, the idea is to use find on the root of your classpath to locate all jars, then runs findclass.sh on all found jars to look for a match. It doesn't handle multi-directories, but if you carefully choose the root you can get it to work.
find ./ -name "filename" or you can do something like find ./ -name "*. jar" to find all the files with the . jar extension. You can also do find ./ -name "*.
Save this as findclass.sh (or whatever), put it on your path and make it executable:
#!/bin/sh find "$1" -name "*.jar" -exec sh -c 'jar -tf {}|grep -H --label {} '$2'' \;
The first parameter is the directory to search recursively and the second parameter is a regular expression (typically just a simple class name) to search for.
$ findclass.sh . WSSubject
The script relies on the -t option to the jar command (which lists the contents) and greps each table of contents, labelling any matches with the path of the JAR file in which it was found.
There is no "official" Java way to do this AFAIK.
The way I usually hunt for it is to use find and jar to look through all jar files in a given tree.
> find . -name \*.jar -print -exec jar tf {} oracle/sql/BLOB.class \; ./v2.6.1/lib/csw_library.jar ./v2.6.1/lib/oracle_drivers_12_01.jar oracle/sql/BLOB.class
If you're on Windows and don't want to install Cygwin, then I suppose you would have to write a batch script to locate the jar files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With