tomcat啟動報錯java.util.zip.ZipException:invalidCENheader(badsignature)

sy9876發表於2018-08-07

war包部署到tomcat裡,啟動時報錯:

Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.JarResourceSet@7e21e65f]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:136)
    at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:699)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 14 more
Caused by: java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid CEN header (bad signature)
    at org.apache.catalina.webresources.JarResourceSet.initInternal(JarResourceSet.java:139)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    ... 17 more
Caused by: java.util.zip.ZipException: invalid CEN header (bad signature)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:214)
    at java.util.zip.ZipFile.<init>(ZipFile.java:144)
    at java.util.jar.JarFile.<init>(JarFile.java:152)
    at java.util.jar.JarFile.<init>(JarFile.java:89)
    at org.apache.catalina.webresources.JarResourceSet.initInternal(JarResourceSet.java:136)
    ... 18 more

根據ZipException報錯,懷疑是jar包有損壞。

為了定位是哪個jar包,使用下面shell指令碼,用jar命令測試jar包:

cd WEB-INF/lib/
for j in *.jar; do echo $j; jar tvf $j > /dev/null ; echo $j done; done

正常的jar包只列印出jar的檔名,損壞的jar包會列印出錯誤資訊

aspectjweaver-1.6.9.jar
java.util.zip.ZipException: invalid CEN header (bad signature)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:225)
        at java.util.zip.ZipFile.<init>(ZipFile.java:155)
        at java.util.zip.ZipFile.<init>(ZipFile.java:126)
        at sun.tools.jar.Main.list(Main.java:1115)
        at sun.tools.jar.Main.run(Main.java:293)
        at sun.tools.jar.Main.main(Main.java:1288)

從maven倉庫中刪除這個jar,重新maven打包。

另外,遇到 invalid LOC header (bad signature) 錯誤,
用jar tvf命令就檢查不出來了。可以使用unzip -t命令檢測。

for j in *.jar; do echo $j; unzip -t $j > /dev/null ; if [ $? -ne 0 ]; then echo $j error; fi; echo $j done; done


mysql-connector-java-5.1.27.jar
warning [mysql-connector-java-5.1.27.jar]:  317386 extra bytes at beginning or within zipfile
  (attempting to process anyway)
file #1:  bad zipfile offset (local header sig):  317386
  (attempting to re-compensate)
mysql-connector-java-5.1.27.jar error


相關文章