tags:

views:

1978

answers:

12

Given a class, org.eclipse.ui.views.navigator.ResourceNavigator for example, how do I find out which jar file to use? I know it's in org.eclipse.ui.ide, but how would I find that out?

Edit: Thank you to all of you who answered. Like many things, there seems to be several ways to skin this cat. I wish javadoc contained this info. So far here are the different methods:

  1. Without Internet, Eclipse or NetBeans:

    for f in `find . -name '*.jar'`;  do echo $f && jar tvf $f | grep -i $1; done
    
  2. If you want to find out locally using Eclipse:

  3. If you want to find out from Internet or you do not have the jar yet:

+1  A: 

Usually, I do jar -vtf foo.jar to get a list of all the class files.
Not the most practical way, but handy. You can combine the result with grep, of course.

PhiLho
This will help you get from JAR --> class, but not the other way around, which is what he asked...
Yuval A
Sorry? My method shows if a class is in a jar, which is pretty much what is asked, if you take time to explore all the jars of your project. Using for as k3andme shows helps, of course.
PhiLho
If you have 1 class file to find in 1000 JARs, you're in a problem... (And this is not unusual, at my workplace I work with thousands of JARs)
Yuval A
+2  A: 

Use a class/JAR locator:

http://classlocator.sourceforge.net/

[EDIT] It isn't obvious, even from ClassLocator's docs (!) but it seems to be an Eclipse plugin.

Yuval A
+1  A: 

If you have the jar in your class path / project path hit CTRL-SHIFT-T and type the name ... the jar will be displayed at the bottom.

If you haven't the class in your build path a) put together a dummy project containing all the jars b) I think there is a plugin to find jars from IBM Alphaworks (but that might be kind of outdated)

pkliem
Ctrl+Shift+T? In what program? What system?
PhiLho
+3  A: 

Use this: netbeans plugin

Or jarFinder service

iberck
+3  A: 

You also have this eclipse plugin: jarclassfinder

The user enters the name of the class not found (or the name of the class that the Java project needs to access). The plug-in will search the selected directory (and subdirectories) for JAR files containing that class.

All results are displayed in a table in a custom view. The user can then browse this table and select the JAR file to add to his Java project's build path. The user then right-clicks on the entry in the table and, from the context menu, selects the build path to which to add it.

VonC
+4  A: 

To answer the question, there is no real way to know which jar to use. Different versions will have potentially different behaviour.

When it comes to locating a jar which contains a given class, I use:

for f in `find . -name '*.jar'`;  do echo $f && jar tvf $f | grep -i $1; done

This will highlight any jar containing the classname passed in as a parameter in any subfolder.

Another good way to find a class is to use the maven repos search.

A: 

I'm not sure I really understand the question, but if you're looking to verify that your class is really in the jar, you can always look through the jar itself, and for that you don't need any Eclipse plugins or specialized external application.

JAR (Java ARchive) files are nothing more than ZIP files. All you have to do is unzip the jar, or even view it using a zip-reading application. Under Windows XP, for example, this comes built into the operating system. How convenient.

Hope this helped...

Yuval =8-)

Yuval
Sometimes, it's not obvious which jar file contains the class that you are interested in.
eed3si9n
+2  A: 

I use FindJar.com. It lists all known packages that contain any given class! It's incredibly helpful.

Kieveli
It didn't find org.eclipse.ui.views.navigator.ResourceNavigator. http://www.jarfinder.com/ worked.
eed3si9n
oracle.jdbc.driver.OracleDriver jarfinder didn't find it and findjar did.
Kieveli
A: 

In Intellij IDEA you just ctrl-click on class name and you are will be moved to pseudo source code of that class, and title of window will be like c:\path\to\lib.jar!\com\something\ClassName.class

Pavel Feldman
A: 

Also check http://javacio.us/.

Adi
I don't see jar file in the search result.
eed3si9n
A: 

IntelliJ IDEA plugin (Class Hunter)

Ralkie
A: 

You could also try Jarvana to find the jar files for a particular class.