Which Jar is my Java class in? 

There are 2 notes for this topic, click above title to see all notes.
Joined:
04/09/2007
Posts:
753

August 10, 2007 19:53:32    Last update: August 10, 2007 19:53:32
As a Java developer, I often need to find out which Jar file to include on my classpath in order to fix some compilation error (undefined package, class etc). This is a little Perl script I wrote to facilitate this task.

#!/bin/perl
# find jar containing specified file
if ($#ARGV != 1) {
    print "Usage: findJar.pl <directory> <filespec>\n";
    exit;
}

$dir = $ARGV[0];
$find = $ARGV[1];

opendir(DIR, $dir) or die "Can't opendir $dir: $!";
@files = grep {/\.jar/} readdir(DIR);
closedir DIR;

for $file (@files) {
    @flist = grep {/$find/} `jar -tf $dir/$file`;
    if (@flist) {
        print "$file:\n";
        print join("", @flist), "\n"; 
    }
}
Share |
| Comment  | Tags