Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

linux

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?

like image 922
szxnyc Avatar asked Jan 19 '14 01:01

szxnyc


1 Answers

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"
like image 197
yǝsʞǝla Avatar answered Nov 14 '22 22:11

yǝsʞǝla