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

前端 未结 17 1277
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 09:47

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 fin

相关标签:
17条回答
  • 2020-12-02 09:54

    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.

    0 讨论(0)
  • 2020-12-02 09:54

    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.

    0 讨论(0)
  • 2020-12-02 09:54

    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

    0 讨论(0)
  • 2020-12-02 09:56

    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)

    0 讨论(0)
  • 2020-12-02 09:59

    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.

    0 讨论(0)
  • 2020-12-02 10:00

    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.

    0 讨论(0)
提交回复
热议问题