Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl # author: vladb # date: 2004-09 # # Searches for classes in a set of jar files # that match a given pattern. use Getopt::Long; use Data::Dumper; use strict; ##--------------------------------------------- ## CONFIG ##--------------------------------------------- @cfg::options = ("help|h","s"); $cfg::unzip = "/usr/5bin/unzip"; ##--------------------------------------------- ## MAIN ##--------------------------------------------- my %opts; GetOptions(\%opts, @cfg::options); help() if ($opts{help}); my $pattern = shift; # replace all / with . $pattern =~ s/\//\./g; my @jars; if (@ARGV == 1) { # expand classpath vars @jars = split(":", shift); } else { @jars = @ARGV; } my (%found, $cmd, $found); for my $jar (@jars) { print "Searching $jar ...\n"; $cmd = "$cfg::unzip -l $jar"; my $pid = open(CMD, "-|"); unless ($pid) { exec($cmd) || die "can't exec '$cmd': $!"; } while (<CMD>) { next unless /(.*?)([^\s\t]+\.class)/; my $info = $1; my $class = $2; if ($class =~ /$pattern/) { $found = 1; $info =~ s/^[\s\t]+//o; $info =~ s/[\s\t]+$//o; $found{$jar}{$class} = $info; } } close(CMD) || warn "failed to close CMD: $?"; } unless ($found) { print "No classes found!\n"; exit; } for my $jar (keys %found) { print "Found in $jar"; if (exists $opts{s}) { print " - " . scalar keys(%{$found{$jar}}) . "\n"; next; } print ":\n"; for (sort keys %{$found{$jar}}) { my $info = $found{$jar}{$_}; s/\.class$//o; s/\//\./g; print " " . $_ . " ($info)\n"; } } ##--------------------------------------------- ## SUBROUTINES ##--------------------------------------------- sub help { print qq~ jfind [-help] [-s] <pattern> <jars ...> Searches for java classes matching a pattern in a set of given jar files or classpath. Class <pattern> could contain /. E.g.: javax/ejb/EJBObject the script will convert all / to . EXAMPLES: jfind digester *.jar jfind -s digester *.jar Search classpath... jfind org.foo.Bar /usr/lib/foo.jar:/usr/lib/bar.jar ~; exit; }

In reply to jfind - java class search by vladb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found