jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes how to find which jar contains a given method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to find which jar contains a given method" Watch "how to find which jar contains a given method" New topic

how to find which jar contains a given method

richard ladson

Joined: Mar 07, 2003
Posts: 11
I often try to run a java sample that I see published somewhere. When I try to compile the code the compiler often complains that it cannot satisfy the "import" statements.

I know how to set classpath to point to a jar file, and I know how to use "import" to access dependent classes, but I do not know how to find which jar contains the dependent classes/methods that I need.

What I do is:
1) Guess which jar file might contain the desired class, then run pkzip to inspect the contents of the jar.
2) Search (grep) all jars in my file system to identify the files that contain the name of the desired method.
3) Use Google to find some information on the net to give me a clue as to where to find the desired jar

Is there a better way?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
A similar problem I've found a good tool for is when you have a bunch of JARs in your classpath, and you know one of them has the class you're looking for, but you don't know which one. JWhich, described in this JavaWorld article will do this for you.

How could this help you? If you create a classpath with all your JARs, you could use it to search all of them with one command.

Now, you mentioned "method" instead of "class" twice. If you need to see what methods a class has, you can use the javap command that comes with the JDK. However, I don't know of a way to search for a method in all classes of a JAR if that's indeed what you need.
Andris Jekabsons
Ranch Hand

Joined: Jan 20, 2004
Posts: 82
I use Windows, so what I've done is added a "view" action for the jar file type. Then I just find one or more jars that might be the ones, rh-click and view them one at a time. Normally it gives enough time to see the contents of the jar and whether it has the needed directory structure.
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

A good tool is Jarhoo, which maintains a catalog of various fairly standard JAR files. It's extensive enough for general purpose, but if you're using something aesoteric (or even some commercial apps, as it concentrates mostly on open-source .jars) then it won't help.
[ January 14, 2005: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
I agree. Here's the link: http://aspose.com/file-tools
subject: how to find which jar contains a given method
jQuery in Action, 3rd edition