Wednesday, 13 June 2018

How to check if a jar file is corrupted

Sometimes jar files get corrupted and we will get errors like below when we will run the file.

 $ java -jar test.jar
Error: Invalid or corrupt jarfile test.jar

When we try to see the content with jar -tvf test.jar.

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:127)
        at java.util.zip.ZipFile.<init>(ZipFile.java:88)
        at sun.tools.jar.Main.list(Main.java:977)
        at sun.tools.jar.Main.run(Main.java:222)
        at sun.tools.jar.Main.main(Main.java:1147)

Run below command. If this is giving proper output like below then it is not corrupted.
It should give information about the classes present in that jar file and few others.
This jar file may work with -cp command. This usually happens if you use prefix with /META-INF/MANIFEST.MF
testuser@indl123!:testuser> unzip -lv RunDbSttm.jar
Archive:  RunDbSttm.jar
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Defl:N        2   0% 07-20-2016 11:49 00000000  META-INF/
      68  Defl:N       67   2% 07-20-2016 11:49 0a41c062  META-INF/MANIFEST.MF
    3653  Defl:N     2022  45% 07-20-2016 11:48 e8c11d5d  RunDbSttm.class
--------          -------  ---                            -------
    3721             2091  44%                            3 files


No comments:

Post a Comment

Thank You for your valuable comment

Difference between class level and object locking and static object lock

1) Class level locking will lock entire class, so no other thread can access any of other synchronized blocks. 2) Object locking will lo...