用groovy遍历jar查找目标文件

背景是log4j.properties冲突,有多个,我就怀疑一些lib下的jar包里有这个配置文件了,所以写个程序scan下,

还好用

 

import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

def findJarFile(File zipFile, String target){
	ZipFile zip = new ZipFile(zipFile)
	ZipEntry entry = null
	Enumeration en = zip.entries()
	while (en.hasMoreElements()) {
		entry = en.nextElement()
		if (entry.isDirectory()) {
			continue
		}

		if(entry.name.contains(target)){
			println zipFile.name
			println entry
		}
	}
	zip.close()
}

String target = 'log4j.properties'
new File('D:/soft/groovy-1.8.0/lib').eachFile{
	if(it.name.endsWith('.jar'))
		findJarFile(it, target)
}
 

你可能感兴趣的:(用groovy遍历jar查找目标文件)