Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: How do I know which jar file to use given a class name?

Tags:

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:

    • JAR Class Finder Plug-in
    • Class Locator Plug-in
  3. If you want to find out from Internet or you do not have the jar yet:

    • jarFinder
    • findjar.com
like image 999
Eugene Yokota Avatar asked Nov 08 '08 20:11

Eugene Yokota


People also ask

How do I know what class a jar file is?

To find the . jar files that contain a class, you can use the FindClass.sh script. First go to a UNIX installation of Sterling Platform/MCF. If the FindClass.sh script already exists it should be in your $YFS_HOME directory or your $YFS_HOME/lib directory.

How can I tell which Java jar is compiled with?

Download a hex editor and open one of the class files inside the JAR and look at byte offsets 4 through 7. The version information is built in. Note: As mentioned in the comment below, those bytes tell you what version the class has been compiled FOR, not what version compiled it.

How do I know if a jar is in classpath?

A pragmatic way: Class. forName("com. myclass") where com. myclass is a class that is inside (and only inside) your target jar; if that throws a ClassNotFoundException , then the jar is not on you current classpath.

How do you find out which jar file an import comes from?

In Eclipse just do Ctrl-Click on the class name (in import sentence), then Right- Click on . class code, to open a dialog,·and finally chose Declarations-project.


1 Answers

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)

like image 157
pkliem Avatar answered Oct 13 '22 00:10

pkliem