Question


I got this error in Catalina.2011-03-30.log when my display.war file executed on Tomcat. The error is shown below:

Mar 30, 2011 8:01:31 PM org.apache.catalina.startup.ContextConfig init  
SEVERE: Exception fixing docBase for context [/Display]   
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:114)
    at java.util.jar.JarFile.<init>(JarFile.java:135)
    at java.util.jar.JarFile.<init>(JarFile.java:72)
    at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:72)
    at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:48)
    at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:70)
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:104)
    at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:71)
    at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:148)
    at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:886)
    at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:1021)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:279)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.StandardContext.init(StandardContext.java:5602)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4378)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1345)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
    at java.lang.Thread.run(Thread.java:662)  

Mar 30, 2011 8:01:31 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources  

java.lang.IllegalArgumentException: Invalid or unreadable WAR file : error in opening zip file  
    at org.apache.naming.resources.WARDirContext.setDocBase(WARDirContext.java:135)  
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4249)  
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4418)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1345)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
    at java.lang.Thread.run(Thread.java:662)  

Thanks in advance.

Was it helpful?

Solution

Unfortunately, the cause and the solution is not that obvious as Buhake Sindi suggests. I've seen this problem several times before in several forums. I've even experienced it myself at least once. Google gives currently over 500 hits on the exact exception message. All remains unanswered. There are however hints that it works in IDE X, but not on IDE Y and that it works on Server X, but not on Server Y. Or that removing or adding something from/to the WAR works (a typical example can be found here). Nobody has however explained the real root cause in depth.

I think that it has something to do with a combination of the JDK/JRE version used and the file size of the WAR. Here are some things you can try:

  • Try to update/align the JDK/JRE version in your IDE and/or appserver environment.
  • Try to add something to the WAR, some random JAR or JSP file or whatever and then rebuild.

OTHER TIPS

I've encountered the error randomly. I think the cause is quite simple.

It can happen when you create the WAR file and transfer it into the tomcat directory by a "slow" process. In my case it is a tranfer from a remote machine by scp. The tomcat can notice that the file has changed (modification date, etc.) before the transfer is over. It may then try to deploy the incomplete file. It will encounter a zip error.

The same can in theory happen if you copy the file from another directory; though the chances are smaller, since the copy is faster.

To avoid the error altogether, the file should be moved (not copied) from another location on the same disk. Such a move is (I think) atomic.

While I am developing, having the error occur every once in a while is not a big problem, though; when I encounter it I just restart the transfer.

If you are deploying on Linux then make sure it is readable by the user that the tomcat process is running as. Run "chmod +r" to the war file to add read rights to everyone.

Same problem here. war file can be opened by 7-zip.

Edit: I figured out why. "Invalid or unreadable WAR file : error in opening zip file" is definitely a confusing error message. The real reason is simply "Tomcat unable to deploy the war because there are some initializing errors". In my case, my War file is missing a few config files which throws out file not found exception. Different Tomcat version seems to report different errors. On 6.0.26, it correctly reports the error. But on 6.0.32, it reports the confusing "Invalid or unreadable WAR file".

I faced this issue, I didn't add anything or modify anything to my build. But I guess my issue raised because I was directly uploading my war file to remote tomcat7/webapps/ directory.

Solution your war file to intermediate directory like /home/yourusername or something then move to your webapps directory. Probably for me this issue raised because file was not fully uploaded yet and tomcat was trying to extract/deploy it.

Hope this will help someone.

i face same issue many times and finally i found the solution .. exact solution anyway i was using Tomcat 8.0.9 locally for testing and when upload the war file to server i got the error message with unzipping the war .. so i checked the server Tomcat and it was 6 so i installed that version and checked the version of Java on the server and found it 5 so i also make sure that i use version 5 on my local machine. the issue happen with how the war file packing so if you use same version and tomcat it will packed in correct way that server can understand ... another solution .. update the server version to match the one you use locally. they should be the same. hope this will solve your issue.

Aby's specific problem seems to be resolved, but in case someone else stumbles onto this page with the same problem I had...

Make sure that your /opt/solr directory has the correct permissions set. I was following the SolrJetty tutorial before later moving to the Tomcat install. Because my solr user was created with this command:

useradd -d /opt/solr -s /sbin/false solr

the /opt/solr directory was created with permissions 700, so tomcat could not get to the WAR file. Change to 755 and it worked perfectly.

In my case it was file corruption during file transfer caused this issue. Hence it's always a best practice to validate the checksum of the file whenever we transfer it to a remote server.

Make sure your path to the WAR file is correct. I had a typo and this got that same error.

BalusC is right. I encountered this error when I ran my webapp on a Linux box that had the openjdk version of Java installed instead of a regular JDK. After installing a normal JDK and pointing tomcat's JRE_HOME variable to the normal JDK the problem disappeared.

I had the same problem (java.lang.IllegalArgumentException: Invalid or unreadable WAR file). For me, the cause was that I had catalina-6.0.43.jar included in my WAR file. To get rid of the error, I created a new WAR file that didn't include this jar, then Tomcat 7 was able to successfully start the application. Unfortunately, this solution only worked for Tomcat 7. I'm still getting the same error when I try to deploy the exact same WAR on Tomcat 8.

In my case I was using WinSCP to transfer the file. I tried many times with all the suggestions described here. All I did to make it work was restarting the WinSCP and the tomcat could read the file.

Thank you @BalusC. Had same issue. Tried many options. Thought this is because of lib I added to maven without prototype scope and as a result it went to war file as well, corrected, same result. I can open it as a zip and all "looks" good there.

Tried locally (different tomcat version: 7.0.67 versus 7.0.22 I have the issue with) works good. Then tried with 7.0.22 but on different VM (instance) - works good. I suspect there is something with tomcat or probably conflict with other was files (that is only difference with other VM, all including Java is same).

The issue is resolved for me using different tomcat instance.

The Cause is clearly shown:

java.lang.IllegalArgumentException: Invalid or unreadable WAR file : error in opening zip file  

A WAR (Web ARchive) file is a zip file containing your classes, libraries and resources for your web application.

Rename your WAR file from a.war to a.zip. If you can't open the zip file using Winzip/7-Zip/WinRar, rebuild your WAR file again.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top