如何找到一个包含UNIX特定类的jar文件列表 [英] How to find a list of jar files that contains a particular class in unix

查看:161
本文介绍了如何找到一个包含UNIX特定类的jar文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到包含给定,在一个特定的目录(DIR)及其所有子目录搜索jar文件列表。

我试过下面的命令。但它提供了所有包含类文件名的类。结果例如:如果该类 Message.class ,下面的命令出放 HttpMessage.class 象类好。

 找到< D​​IR> -name'的* .jar|而阅读F;做(回声$ F;罐子-tvf $ F | grep的<类别和GT;)来完成 - 打印如果类存在,那么打印类名的jar名。


解决方案

使用的grep 可以找到匹配的罐子,但是,它不能列出类的命名空间。

以下命令组合找到 JAR 命令,将打印出来的与包名类,也是 jar文件的名称

 找到。型的F -name'的* .jar-print0 | xargs的-0 -I'{}'上海-c'罐子TF {} | grep的Message.class&放大器;&安培;回波{}'

您也可以与您的包名搜索象下面这样:

 找到。型的F -name'的* .jar-print0 | xargs的-0 -I'{}'上海-c'罐子TF {} | grep的COM / mypackage中/ Message.class和放大器;&安培;回波{}'

I want to find a list of jar files that contains a given , by searching in a particular directory (DIR) and all its sub directories.

I tried below command. But it provided all the classes that contains the CLASS FILE name.
Eg : If the class is Message.class, following command out put the HttpMessage.class like class as well.

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.

解决方案

Using grep can find the matched jar, however, it cannot list the namespace of the class.

Below command combined with find and jar commands, it will print out the class with package name and also the jar file name.

find . -type f -name '*.jar' -print0 |  xargs -0 -I '{}' sh -c 'jar tf {} | grep Message.class &&  echo {}'

You can also search with your package name like below:

find . -type f -name '*.jar' -print0 |  xargs -0 -I '{}' sh -c 'jar tf {} | grep com/mypackage/Message.class &&  echo {}'

这篇关于如何找到一个包含UNIX特定类的jar文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆