Find a Class in Jars (II)

This one is a follow-up to this post, finding a class in jars under a certain folder. But this time, it is obviously in Ruby:

require 'java'

def scanDir(className, dirname='C:') begin Dir.foreach(dirname) do |filename| next if (filename == "." or filename == "..") if File.directory?(filename) scanDir className, filename elsif File.fnmatch("**.jar", filename) scanJar(className, File.join(dirname, filename)) end end rescue SystemCallError $stderr.print "IO failed: " + $! end end
def scanJar(className, jarfile) entries = java.util.jar.JarFile.new(jarfile).entries entries.each do |entry| if entry.getName().to_s.index(className) != nil puts "#{jarfile}: #{entry}\n" end end end
if ARGV.size == 2 scanDir ARGV[0], ARGV[1] else puts "Usage: jruby search_jar.rb <class_name> <directory>" end

You then call it as follows:

jruby search_jar.rb MyNiceStub C:\application_server\lib

Edit: Ideally, something like Rake’s FileList would make finding the jar in subfolders a trivial task…

 
---

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

---