Find a jar file given the class name?

后端 未结 17 1923
无人共我
无人共我 2020-11-29 18:46

This must be a very basic question for Java developers, but what is the best way to find the appropriate jar file given a class name?

For example, give

相关标签:
17条回答
  • 2020-11-29 19:32

    Given your comment on attempting to handle dependencies, what I would do is focus on which libraries you are using. Knowing this, you will know what jars have to be on the classpath, and you can pay attention to that. There are also dependency management builders (Maven and Ant being two popular ones) that can package up projects with their dependencies inside. However, in the end, it is up to the developer to know which dependencies they have, and to pay attention to the requirements for those dependencies. This is one reason why using an IDE like Eclipse, and build tools like Maven or Ant are so nice in large projects, as when you have 20 dependencies for a project, that can become pretty unmanageable.

    0 讨论(0)
  • 2020-11-29 19:34

    Try findjar.com. If it's in the public domain, you should get it. There's alos mavenjava.com (but that site seems to be down)

    0 讨论(0)
  • 2020-11-29 19:37

    locate .jar | xargs grep com.ibm.websphere.security.auth.WSSubject

    0 讨论(0)
  • 2020-11-29 19:38

    You could try services like:

    • http://www.jarhoo.com/
    • http://www.docjar.com/
    • http://javacio.us/
    • http://merobase.com/

    Or

    • Google Desktop with the Airbear Software's IndexZip Plug-in

    Or

    • A maven enterprise repository with a search feature e.g. Nexus (OFC, this would only work if the jars you're looking for are indexed i.e. installed in the repository)

    PS: Jarhoo has teamed up with Javacio.us to provide 100,000 Java developers with free access to Jarhoo via links integrated with their Google search results. Subscription to Javacio.us is free and open to anyone with a Google account. For more information, please visit the Jarhoo offer page at Javacio.us.

    0 讨论(0)
  • 2020-11-29 19:39

    There is no "official" Java way to do this AFAIK.

    The way I usually hunt for it is to use find and jar to look through all jar files in a given tree.

    > find . -name \*.jar -print -exec jar tf {} oracle/sql/BLOB.class \;
    ./v2.6.1/lib/csw_library.jar
    ./v2.6.1/lib/oracle_drivers_12_01.jar
    oracle/sql/BLOB.class
    

    If you're on Windows and don't want to install Cygwin, then I suppose you would have to write a batch script to locate the jar files.

    0 讨论(0)
  • 2020-11-29 19:39

    In windows powershell you can use this command. It list all the JAR files it encounters, but it has an extra line that's very easy to spot where it also finds your class.

    Get-ChildItem -recurse -Filter *.jar | Foreach {echo $_.fullname; c:\somepath\JDK\BIN\jar tvf $_.fullname | Select-String -pattern "Cabbages.class"}
    
    0 讨论(0)
提交回复
热议问题