如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
当前回答
你可以使用locate和grep:
locate jar | xargs grep 'my.class'
确保在使用locate之前运行updatedb。
其他回答
Eclipse可以做到这一点,只需创建一个(临时的)项目,并将您的库放在项目类路径上。然后你可以很容易地找到课程。
我想到的另一个工具是Java反编译器。它可以一次打开很多罐子,还可以帮助查找类。
使用这个. .你可以在类路径..中找到任何文件。保证. .
import java.net.URL;
import java.net.URLClassLoader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class FileFinder {
public static void main(String[] args) throws Exception {
String file = <your file name>;
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url: urls){
listFiles(file, url);
}
}
private static void listFiles(String file, URL url) throws Exception{
ZipInputStream zip = new ZipInputStream(url.openStream());
while(true) {
ZipEntry e = zip.getNextEntry();
if (e == null)
break;
String name = e.getName();
if (name.endsWith(file)) {
System.out.println(url.toString() + " -> " + name);
}
}
}
}
不知道为什么这里的脚本从来都不适合我。如此:
#!/bin/bash
for i in *.jar; do jar -tf "$i" | grep $1 | xargs -I{} echo -e "$i : {}" ; done
查看JBoss Tattletale;虽然我个人从未使用过,但这似乎是你需要的工具。
不久前,我专门为此写了一个程序:https://github.com/javalite/jar-explorer