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, give
if you are still searching for WSSubject, then jar is wssec.jar. WSSecurityException class inside sas.jar
In Windows, run cmd.exe and type:
for %i in (*.jar) do @jar tvf %i | find "/com/company/MyClass.class"
The jars would have to be in the current directory. For also has a /R option which takes a directory and lets you search recursively.
If Jar.exe isn't in your path, you can do something like @C:\jdk\bin\jar.exe.
I recommend using Maven, Eclipse and m2eclipse.
Step 1 - add specific import
Step 2 - find and download (automatically) desired jar
If the grep on your system (e.g. Solaris) doesn't have -H and --label as used in Dan Dyer's example, you can use:
find . -name '*.jar' -type f | xargs -i bash -c "jar -tvf {}| tr / . | grep WSSubject && echo {}"
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.