Which Jar is my Java class in?
There are 2 notes for this topic, click above title to see all notes.
September 06, 2007 22:22:04 Last update: September 06, 2007 22:22:28
This is an improved version with recursive capabilities.
#!/bin/perl # find jar containing specified file if ($#ARGV != 1) { print "Usage: findJar.pl <directory> <filespec>\n"; exit; } $dir = $ARGV[0]; $find = $ARGV[1]; find_jar($dir, $find); sub find_jar { my ($dir, $find) = @_; opendir(DIR, $dir) or die "Can't opendir $dir: $!"; my @files = grep { /^[^\.]/ } readdir(DIR); closedir DIR; for my $file (@files) { if (-d "$dir/$file") { find_jar("$dir/$file", $find); } elsif (-f "$dir/$file") { if ($file =~ /\.jar$/) { # jar file my @flist = grep {/$find/} `jar -tf $dir/$file`; if (@flist) { print "$dir/$file:\n"; print join("", @flist), "\n"; } } elsif ($file =~ /$find/) { # treat as regular file print "$dir:\n$file\n"; } } } }
Easy email testing with http://www.ximailstop.com