bash - Find for a class file in Linux that is present in JAR -


i trying find jar file contains class using below command given in link : find jar file given class name?

find . -name "*.jar" -exec sh -c 'jar -tf {}|grep -h --label {} genericclassloader' \; 

but getting error :

java.util.zip.zipexception: error in opening zip file         @ java.util.zip.zipfile.open(native method)         @ java.util.zip.zipfile.<init>(zipfile.java:131)         @ java.util.zip.zipfile.<init>(zipfile.java:92)         @ sun.tools.jar.main.list(main.java:997)         @ sun.tools.jar.main.run(main.java:242)         @ sun.tools.jar.main.main(main.java:1167) 

please me in understanding command , how solve error. using bash shell.

there in filesystem, ends *.jar isn't valid archive. debug this, add -print find command:

find . -name "*.jar" -print -exec ... 

this make find print name of file before tries execute sh command.

explanation:

  • find .: find files , folder in current directory
  • -name "*.jar" name ends .jar
  • -exec , execute following command each of them
  • sh -c create new shell , execute ...
  • jar -tf {} test jar archive. (also) prints list of files in archive find replace {} path of archive found
  • | pipe result of jar -tf ...
  • grep search input ...
  • -h print filename each match
  • --label {} since we're reading stdin, grep should use {} (again replaced find) filename
  • genericclassloader search string in output of jar -tf

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -