23

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:

Adriano
  • 19,463
  • 19
  • 103
  • 140
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
  • ugh! Such an ugly way to do that find. I prefer: for f in $(find . -name *.jar); do echo $f && jar tvf $f | grep -i $1; done – Eldelshell Jan 05 '09 at 10:11
  • It's nice that you put together a summary of the answers. @Ubersoldat, why is that so ugly? – luiscolorado Aug 17 '10 at 13:31
  • I hate those nasty back-quotes. I'm spanish, and we don't use them for anything except when we're doing something wrong. Also, they are very hard to read. That's why I prefer $( something ) – Eldelshell Aug 17 '10 at 13:59
  • @eugeneyokota hey, is there a way to search for it inside the code? Like an api or some tool within your code to search for Jar? – amir Dec 31 '21 at 19:23

17 Answers17

22

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
  • 346
  • 1
  • 3
  • 1
    Ctrl+Shift+T? In what program? What system? – PhiLho Nov 08 '08 at 21:00
  • 1
    @PhiLho In Eclipse. That is what the original question was tagged with. – Konstantin Tarashchanskiy Apr 20 '12 at 18:34
  • @KonstantinNaryshkin Doh! for missing it, -1 on the original post for only relying on tags, missing to indicate that in the title or the message itself. Given that most answers here just are outside of Eclipse, I am not the only one to have missed that. (Or we believed it was only to find Eclipse classes?) The generic answers are useful anyway. Side notes: thanks for answering my question (better late than never); and giving an answer with a keyboard shortcut is a bit brittle, since one can change them (I do, but not this one, though). Here, it is the shortcut for the Open Type functionality. – PhiLho Apr 25 '12 at 08:33
19

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
13

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.

arvindwill
  • 1,960
  • 1
  • 23
  • 39
8

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.

user28791
  • 121
  • 1
5

For me this works fine:

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

Regards

user2039378
  • 51
  • 1
  • 1
3

Use this: netbeans plugin

Or jarFinder service

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
iberck
  • 2,372
  • 5
  • 31
  • 41
3
**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

2

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.

PhiLho
  • 40,535
  • 6
  • 96
  • 134
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
2

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

Kieveli
  • 10,944
  • 6
  • 56
  • 81
1

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
  • 40,535
  • 6
  • 96
  • 134
  • This will help you get from JAR --> class, but not the other way around, which is what he asked... – Yuval Adam Nov 08 '08 at 20:14
  • 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 Nov 08 '08 at 21:06
  • 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 Adam Nov 09 '08 at 08:25
1

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
  • 4,621
  • 7
  • 30
  • 31
1

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)

slfan
  • 8,950
  • 115
  • 65
  • 78
0

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

amphibient
  • 29,770
  • 54
  • 146
  • 240
0

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

0

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
  • 7,987
  • 12
  • 40
  • 54
0

Also check http://javacio.us/.

Adisesha
  • 5,200
  • 1
  • 32
  • 43
0

IntelliJ IDEA plugin (Class Hunter)

Ralkie
  • 3,736
  • 3
  • 25
  • 25