利用getResources可以使用classLoader查找当前项目的classpath下,所有的jar包路径
public class Test {
public static void main(String[] args) throws Exception{
ClassLoader classLoader = Test.class.getClassLoader();
//只能搜索jar包内的字符,比如文件夹org,com,文件名a.xml
Enumeration<URL> paths = classLoader.getResources("META-INF");
int count = 0;
while (paths.hasMoreElements()){
String path = paths.nextElement().toString();
if (path.indexOf("jdk") == -1){
count++;
System.out.println(path);
}
}
System.out.println(count);
}
}