我想通过在特定目录(DIR)及其所有子目录中搜索来查找包含给定的jar文件列表.
我试过下面的命令.但它提供了包含CLASS FILE名称的所有类.
例如:如果类是Message.class,则在命令输出后也输入HttpMessage.class类似的类.
find <DIR> -name '*.jar' | while read F; do (echo $F; jar -tvf $F | grep <class>) done - prints the jar name if the class exists then prints the class name.
Run Code Online (Sandbox Code Playgroud)
使用grep可以找到匹配的jar,但是,它不能列出类的命名空间.
下面的命令结合了find和jar命令,它将打印出包含名称和jar文件名的类.
find . -type f -name '*.jar' -print0 | xargs -0 -I '{}' sh -c 'jar tf {} | grep Message.class && echo {}'
Run Code Online (Sandbox Code Playgroud)
您也可以使用下面的包名搜索:
find . -type f -name '*.jar' -print0 | xargs -0 -I '{}' sh -c 'jar tf {} | grep com/mypackage/Message.class && echo {}'
Run Code Online (Sandbox Code Playgroud)