This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

how to find which jar contains a given method

 
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?
 
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.
 
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.
 
Bartender
Posts: 1840
Eclipse IDE Ruby Java
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!