Skip to content

Instantly share code, notes, and snippets.

@mebubo
Created August 24, 2012 08:19
Show Gist options
  • Save mebubo/3447425 to your computer and use it in GitHub Desktop.
Save mebubo/3447425 to your computer and use it in GitHub Desktop.
Find classes in jars
#!/usr/bin/env python
import sys, os
from zipfile import ZipFile
# Given a directory of jar files and a pattern, list all files that
# contain matching classes, and the matching classes
#
# Usage: findclass.py <dir> <pattern>
dir, pattern = sys.argv[1:3]
for filename in os.listdir(dir):
if filename.endswith(".jar"):
matches = [path for path in ZipFile(filename, "r").namelist()
if pattern in path]
if matches:
print "%s:" % filename
for m in matches:
print "\t%s" % m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment