我用Python编写了一个脚本来清理jar的档案(我知道我需要的类Class Dependency Analyzer) 这是我的剧本:
def deleteJarEntrie(pJarPath) :
# Dictionary contains className of jar file for key
# and a list of class for value
for key in myDict.keys():
zin = zipfile.ZipFile (pJarPath+key, 'r')
zout = zipfile.ZipFile (key, 'w')
# for each entry in zip file
for item in zin.infolist():
# if the className of the file finished by one “/” it is a directory
# thus I do not reiterate values of the dictionary
if (item.filename[-1:] != "/"):
# For each value of my dictionary (the value are the classes which I need)
for value in myDict.get(key):
buffer = zin.read(item.filename)
className = item.filename.split("/")
className = className[len(className)-1]
if (item.filename == value):
zout.writestr(item, buffer)
print item.filename
zout.close()
zin.close()'
问题是item.filename永远不会取值的类文件名,item.filename只取目录值,但它可以取值MANIFEST.MF。
例如:
我在/org/test/myClass.class中有一个类
- > item.filename = / org / test /
我在/META-INF/MANIFEST.MF
中有一个清单- > item.filename = /META-INF/MANIFEST.MF
我不明白为什么我看不到类文件......
感谢您的回答,对不起,如果我的英语不正确。