如何在大量 jar 文件中找到特定的类名?
How would you find a particular class name inside lots of jar files?
(寻找实际的类名,而不是引用它的类.)
(Looking for the actual class name, not the classes that reference it.)
推荐答案Unix
在 Linux、其他 Unix 变体、Windows 上的 Git Bash 或 Cygwin 上,使用 jar(或 unzip -v)、grep, 和 find 命令.
Unix
On Linux, other Unix variants, Git Bash on Windows, or Cygwin, use the jar (or unzip -v), grep, and find commands.
以下列出了与给定名称匹配的所有类文件:
The following lists all class files that match a given name:
for i in *.jar; do jar -tvf "$i" | grep -Hsi ClassName && echo "$i"; done如果您知道要搜索的 Java 档案的完整列表,您可以使用(符号)链接将它们全部放在同一目录中.
If you know the entire list of Java archives you want to search, you could place them all in the same directory using (symbolic) links.
或者使用find(区分大小写)查找包含给定类名的JAR文件:
Or use find (case sensitively) to find the JAR file that contains a given class name:
find path/to/libs -name '*.jar' -exec grep -Hls ClassName {} ;例如,要查找包含 IdentityHashingStrategy 的存档名称:
For example, to find the name of the archive containing IdentityHashingStrategy:
$ find . -name '*.jar' -exec grep -Hsli IdentityHashingStrategy {} ; ./trove-3.0.3.jar如果 JAR 可以在系统中任何地方并且 locate 命令可用:
If the JAR could be anywhere in the system and the locate command is available:
for i in $(locate "*.jar"); do echo "$i"; jar -tvf "$i" | grep -Hsi ClassName; done语法变体:
find path/to/libs -name '*.jar' -print | while read i; do jar -tvf "$i" | grep -Hsi ClassName && echo "$i"; done视窗
打开命令提示符,切换到包含 JAR 文件的目录(或祖先目录),然后:
Windows
Open a command prompt, change to the directory (or ancestor directory) containing the JAR files, then:
for /R %G in (*.jar) do @jar -tvf "%G" | find "ClassName" > NUL && echo %G这是它的工作原理:
网页
使用扫描搜索引擎://www.findjar/" rel="noreferrer">JAR 文件.
Web
Use a search engine that scans JAR files.
更多推荐
在几十个 JAR 文件中的某个地方找到一个类?
发布评论