Linux cmd to search for a class file among jars irrespective of jar path

前端 未结 8 946
灰色年华
灰色年华 2021-01-29 23:58

I want to search for a particular class file among many jar files without giving the location of each jar file.

Is this possible with a simple command?

I tried t

8条回答
  •  清歌不尽
    2021-01-30 00:37

    Most of the solutions are directly using grep command to find the class. However, it would not give you the package name of the class. Also if the jar is compressed, grep will not work.

    This solution is using jar command to list the contents of the file and grep the class you are looking for.

    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 Hello.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/Hello.class &&  echo {}'
    

提交回复
热议问题