Reputation: 701
I am trying to find a JAR file which contains my class using below command given in this link : Find a jar file given the class name?
find . -name "*.jar" -exec sh -c 'jar -tf {}|grep -H --label {} GenericClassLoader' \;
but I am getting error as :
java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:131)
at java.util.zip.ZipFile.<init>(ZipFile.java:92)
at sun.tools.jar.Main.list(Main.java:997)
at sun.tools.jar.Main.run(Main.java:242)
at sun.tools.jar.Main.main(Main.java:1167)
Please help me in understanding the command and also how solve this error. I am using bash shell.
Upvotes: 3
Views: 5279
Reputation: 328604
There is something in your filesystem, which ends with *.jar
but which isn't a valid archive. To debug this, add -print
to the find
command:
find . -name "*.jar" -print -exec ...
This will make find
print the name of the file before it tries to execute the sh
command.
Explanation:
find .
: Find all files and folder in the current directory -name "*.jar"
whose name ends with .jar
-exec
and execute the following command for each of them sh -c
Create a new shell and execute ... jar -tf {}
Test a JAR archive. This (also) prints a list of files in the archive find
will replace the {}
with the path of the archive it found |
pipe the result of jar -tf
into ... grep
search the input for ... -H
Print the filename for each match--label {}
Since we're reading from stdin, grep
should use {}
(again replaced by find) as the filename GenericClassLoader
search for this string in the output of jar -tf
Upvotes: 4