There are more robust apps out there that find a Java class given a bunch of jars, but I mostly use this script. Usage is:
jargrep ClassName /scratch/a/dir/with/jars
Script:
#!/bin/bash # usage: jargrep searchstring dir for jar in `find $2 -name '*.jar' -type f` do echo $jar jar tvf $jar | grep "$1" done
I leave the echo of each jar searched in so I know how it's progressing, but it makes it hard to tell if the class was actually found when there are a lot of jars.
2 Comments
… i'd use:
jar tvf $jar | grep -q "$1" && echo $jar
Yes, that's a good option too. I like the "always" echo $jar so I know if I've accidentally set it on a huge NFS mount that will keep it busy for hours. One minor drawback of grep -q is that you find out if the classname is in the jar, but not at a glance what the FQN of the class is.
Post a Comment