Question

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:

Was it helpful?

Solution

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.


Update 2013, as I mention in "searching through .jar files eclipse", it is no longer maintained, and the alternatives are sparse.

As sunleo comments below:

with Eclipse, Ctfl+Shift+T remains the easiest alternative to look for a type
(with the jar name displayed in the status bar).


user862268 comments below:

For mac, it is cmd+shift+T in Eclipse to find the class and associated jar.

OTHER TIPS

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)

go for Ctrl+Shift+T in Eclipse IDE

Open Type dialog appears where you enter the class name. after that package identifier and jar destination get displayed.

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.

For me this works fine:

find * -type f -name '*.jar' -exec grep -l 'TestClass.class' '{}' \;

Regards

Use this: netbeans plugin

Or jarFinder service

**shell> find . -name "*.jar" | xargs -i -t \jar tvf {} | grep [TheClassNameYouAreLookingFor]**

For example, if you are looking for a class LogFactory.class on list of apache commons jars, below command would work

shell> find apache-commons/ -name "*.jar" | xargs -i -t \jar tvf {} | grep LogFactory.class

jar tvf apache-commons/commons-beanutils-1.7.0.jar

jar tvf apache-commons/commons-fileupload-1.2.1.jar

jar tvf apache-commons/commons-lang-2.3.jar

**jar tvf apache-commons/commons-logging-1.1.jar**

**21140 Tue May 09 23:08:12 EDT 2006 org/apache/commons/logging/LogFactory.class**

jar tvf apache-commons/commons-net-1.3.0.jar

The above result indicates that the match is commons-logging-1.1.jar

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.

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

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.

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

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-)

Also check http://javacio.us/.

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

I vote for CTRL-SHIFT-T because it is already included in Eclipse. I actually dropped jarclassfinder.jar in the plugins dir within the eclipse installation but still couldn't find the plugin in Eclipse GUI

if you tell eclipse to open a declaration (F3) or implementation (Navigate->Open Implementation) and you get popped into an un-editable edit window, you can see the path to the jar file by right-clicking the editor window and choosing 'show in breadcrumbs'

my find unix based:

find . -name "*.jar" -print -exec jar -tf {} \; >outputfile

edit output file to find what you want (instead of grep)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top