java.util.zip.ZipException:打开 zip 文件时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3683142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:59:32  来源:igfitidea点击:

java.util.zip.ZipException: error in opening zip file

javaspring

提问by jonney

i am geting this strange exception below:

我在下面收到这个奇怪的异常:

INFO: Deploying web application archive ZangV3Spring.war
10-Sep-2010 08:46:38 org.apache.catalina.startup.ContextConfig init
SEVERE: Exception fixing docBase for context [/ZangV3Spring] 
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:80)
    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:110)
    at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:709)
    at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:838)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:331)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:312)
    at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:292)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:100)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:129)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:785)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:763)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:558)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:987)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:540)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1458)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:338)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1186)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1340)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1349)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1329)
    at java.lang.Thread.run(Thread.java:619)
10-Sep-2010 08:46:38 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:141)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4432)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4582)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:138)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:785)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:763)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:558)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:987)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:540)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1458)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:338)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1186)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1340)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1349)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1329)
    at java.lang.Thread.run(Thread.java:619)

If i remove this bean from my xml it will build and deploy fine:

如果我从我的 xml 中删除这个 bean,它将很好地构建和部署:

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

The rest of my xml content is this:

我的 xml 内容的其余部分是这样的:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/jee
       http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">

    <!-- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd -->

    <!-- Config properties files -->



    <!-- Hibernate database stuff -->


    <bean id="fileDownload" class="com.kc.models.FileManipulator"></bean>

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>properties/jdbc.properties</value>
            </list>
        </property>
    </bean>


    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${database.driver}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.user}" />
        <property name="password" value="${database.password}" />
        <property name="maxActive" value="${database.maxConnections}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
    </bean>



    <!--

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionsFactory" ref="sessionFactory"></property>
    </bean>


     -->
</beans>

回答by NateFriedman

I got this same error when tomcat6 was looking for the war file in the wrong location. IMHO very misleading error message. Changed the configuration to point to the right place and it worked.

当 tomcat6 在错误的位置寻找 war 文件时,我遇到了同样的错误。恕我直言,非常具有误导性的错误信息。将配置更改为指向正确的位置并且它起作用了。

回答by Bozho

It appears that your war file is corrupted. Try re-creating it. And try opening it with a zip program (like winrar)

您的war文件似乎已损坏。尝试重新创建它。并尝试使用 zip 程序(如 winrar)打开它

回答by Deepak Kumar Sharma

Once clear all your .jar associated project and then build them on automatically. Now you can start you jboss server which will resolve your problem. This solved at my end.

清除所有与 .jar 相关的项目,然后自动构建它们。现在你可以启动你的 jboss 服务器来解决你的问题。这在我的最后解决了。

回答by Karvari Ellingson

True, the .war file my be corrupted... OR you may just need to change the permissions on it. I just ran into this as well. Luckily I was upgrading and had the old .war file to compare to.

没错,.war 文件可能已损坏...或者您可能只需要更改它的权限。我也刚碰到这个。幸运的是我正在升级并且有旧的 .war 文件可以比较。

had -rw-r--r-- on the old one and -rw-r----- on the new one. A quick:

在旧的上有 -rw-r--r-- ,在新的上有 -rw-r----- 。快速:

$ sudo chmod 644 <filename>.war 

fixed it right up.

把它修好了。

回答by Ivan

have same erorr, but it second error in log, first:

有相同的错误,但它在日志中出现第二个错误,首先:

SEVERE: Exception fixing docBase for context [/readfromnet] java.util.zip.ZipException: error in opening zip file

严重:上下文的异常修复 docBase [/readfromnet] java.util.zip.ZipException:打开 zip 文件时出错

so, i think that Tomcat begin unzip war before it fully uploaded

所以,我认为Tomcat在完全上传之前就开始解压War