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