简体   繁体   中英

Search or list Java classes in classpath (ncluding JARS) via command line

I really like the javap command line program to decompile and inspect classes however most of the time I can't recollect the fully qualified package name of a class:

javap java.nio.file.Files

If I don't know the package name then I resort to using Google. Is there a built-in java program or slick Linux command that could search and list all the matching packages of a given class name?

Searches all jars:

find <path> -name "*.jar" -exec jar -tf {} \; | grep "/<classname>\.class\$"

example:

find ~/.ivy2/ -name "*.jar" -exec jar -tf {} \; | grep "/Filter\.class\$"

output:

javax/servlet/Filter.class
javax/servlet/Filter.class
javax/servlet/Filter.class
org/scalatest/Filter.class
org/scalatest/Filter.class
org/fusesource/scalate/filter/Filter.class
org/fusesource/scalate/filter/Filter.class
scala/tools/scalap/scalax/rules/Filter.class
org/apache/ivy/util/filter/Filter.class
com/foursquare/fongo/impl/Filter.class
com/foursquare/fongo/impl/Filter.class
com/foursquare/fongo/impl/Filter.class
shapeless/Filter.class

I'm not personally in love with this solution.

To search all class files just use find :

find <path> -name "*.class"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM