Welcome, guest | Sign In | My Account | Store | Cart

This program iterate through .jar files and print .class files from it

Python, 41 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# -*- coding: utf8 -*-

# this program shows .class files from *.jar files

__version__ = '$Id: show_jars_classes.py 743 2010-07-22 09:10:31Z mn $'

# author: Michal Niklas 

import sys
import zipfile
import glob

def show_jar_classes(jar_file):
	"""prints out .class files from jar_file"""
	zf = zipfile.ZipFile(jar_file, 'r')
	try:
		lst = zf.infolist()
		for zi in lst:
			fn = zi.filename
			if fn.endswith('.class'):
				print(fn)
	finally:
		zf.close()


def main():
	jars = glob.glob('*.jar')
	if not jars:
		sys.stderr.write('No .jar files found!\n')
	else:
		for jf in jars:
			print('\n\n-- %s --' % (jf))
			show_jar_classes(jf)


if __name__ == '__main__':
	if '--version' in sys.argv:
		print(__version__)
	else:
		main() 
Created by Michal Niklas on Thu, 22 Jul 2010 (MIT)
Python recipes (4591)
Michal Niklas's recipes (13)

Required Modules

  • (none specified)

Other Information and Tasks