Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to find which jar contains a given method

 
richard ladson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic