Find a jar file given the class name?

后端 未结 17 2071
无人共我
无人共我 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:25

    To search all jars under the current directory and return the one(s) that contain class a.b.c.D do a:

    find . -iname *.jar | while read JARF; do jar tvf $JARF | grep a/b/c/D.class && echo $JARF ; done
    

    It will report all instances of class a.b.c.D (or classes with a similar suffix) and will only print the jars that contain it.

    Typical output:

    $ find . -iname *.jar | while read JARF; do jar tvf $JARF | grep Log.class && echo $JARF ; done
    479 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/Log.class
    3714 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/impl/Log4JCategoryLog.class
    1963 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/impl/NoOpLog.class
    9065 Fri Oct 10 18:19:40 PDT 2003 org/apache/commons/logging/impl/SimpleLog.class
    ./WebContent/WEB-INF/lib/commons-logging.jar
    

提交回复
热议问题