Find class files in a directory tree full of .jar's with a free open source tool for the Windows command line, Mac OS X Terminal or Linux shell.
imagine you are evaluating an open source package named "foobox", and try to compile an example source like this: javac org\foobox\examples\barmodel\HelloWorld.java
getting an error:
org\foobox\barmodel\Driver.java:38: package org.barbox.util does not exist
obviously, some .class files or .jars are missing in the classpath. but how do you find out instantly where "barbox" classes are located?
download the free swiss file knife, then type in the package root directory:
sfk list -zip . >lslr
this creates an index text file "lslr", containing
- all filenames in the current directory tree (and all subdirectories)
- all filenames within all .jar and .zip files
sfk find lslr barbox util
creating output like this:
external\BarBox-0.9-dev.jar\org/barbox/util/ external\BarBox-0.9-dev.jar\org/barbox/util/BoundingBox.classthe result: classes with the package "org.barbox.util" are located within external\BarBox-0.9-dev.jar, so add this to your compilation classpath.
this is a first solution, but it can be done even more easily,
through creating an sfk alias called "gls!":
sfk alias gls! = "sfk list -zip . >lslr & sfk find lslr"
(windows syntax. the linux shell may need adaptions concerning "!" and "&".)
gls stands for "grep the lslr index". (sfk will create a small batch file from the above, adding things like %1 %2 %3 automatically.) now, the first time you enter a new package's main directory, type for example
gls! barbox util
which will
- create the very detailed index file "lslr"
- search instantly for the words "barbox" AND "util" accross this index
sfk alias gls = sfk find lslr
which simply searches instantly in the existing lslr.
instant interface listing with javap
staying with above example, if you know there is a BoundingBox.class, how do you turn the line
external\BarBox-0.9-dev.jar\org/barbox/util/BoundingBox.class(as extracted from lslr) into a command
javap -classpath external\BarBox-0.9-dev.jar org.barbox.util.BoundingBox
to get the interface of BoundingBox listed instantly? create another alias, "javap!" this way (windows syntax example; type all in one line):
sfk alias javap! "sfk echo %1 +filt -rep \"_.jar\_.jar _\"
-rep _/_._ -rep _.class__ -blocksep \" \"
-form \"javap -classpath $col1 $col2\" +run $text -yes"
then, if "external\BarBox-0.9-dev.jar\org/barbox/util/BoundingBox.class" is listed
in the command shell, double-click on it (provided that QuickEdit and Insert
is configured ON with your shell), press right button to copy to clipboard.
type
javap!
and press right mouse button again to paste the copied text:
javap! external\BarBox-0.9-dev.jar\org/barbox/util/BoundingBox.class
press ENTER, and the class interface should be listed.
further reading:
how to list nested .zip and .jar contents everywhere in a directory tree.