Jetty 上的 JSF2 随机给出“zip 文件已关闭”但在从 Maven jetty 插件运行时有效 (jetty:run)

发布于 2024-12-09 14:36:13 字数 3184 浏览 1 评论 0原文

我的 JSF Web 应用程序在访问文件(如图像、css、js)时随机出现错误:“zip 文件已关闭”。它部署在 Jetty 7 上。看起来其中一些文件未加载(页面上缺少一些图像)。

java.lang.IllegalStateException: zip file closed
    at java.util.zip.ZipFile.ensureOpen(ZipFile.java:403)
    at java.util.zip.ZipFile.entries(ZipFile.java:298)
    at java.util.jar.JarFile.entries(JarFile.java:217)
    at org.eclipse.jetty.util.resource.JarFileResource.list(JarFileResource.java:261)
    at org.eclipse.jetty.util.resource.ResourceCollection.list(ResourceCollection.java:421)
    at org.eclipse.jetty.util.resource.Resource.getListHTML(Resource.java:509)
    at org.eclipse.jetty.servlet.DefaultServlet.sendDirectory(DefaultServlet.java:741)
    at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:564)

当我使用 jetty:run 或 jetty:run-war 从 Maven 插件 (7.x) 运行它时,我不会收到任何错误。 更重要的是,仅当在独立码头上运行时,访问Web上下文的根路径才会出现“zip文件已关闭”错误,但从maven插件运行时不会出现此类错误,然后是那些目录视图。

我的 web.xml:

   <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

pom.xml:

  ....
  <dependencies>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.3</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.3</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
</dependencies>
....
<plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>7.5.1.v20110908</version>

        <configuration>
            <scanIntervalSeconds>10</scanIntervalSeconds>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>com.sun.faces</groupId>
                <artifactId>jsf-api</artifactId>
                <version>2.1.3</version>
            </dependency>
            <dependency>
                <groupId>com.sun.faces</groupId>
                <artifactId>jsf-impl</artifactId>
                <version>2.1.3</version>
            </dependency>                    
        </dependencies>
    </plugin>   

知道它是什么吗?

my JSF web app is giving randomly error: "zip file closed" when accessing files (like images, css, js). It is deployed on Jetty 7. It looks like some of those files are not loaded (some images are missing on a page).

java.lang.IllegalStateException: zip file closed
    at java.util.zip.ZipFile.ensureOpen(ZipFile.java:403)
    at java.util.zip.ZipFile.entries(ZipFile.java:298)
    at java.util.jar.JarFile.entries(JarFile.java:217)
    at org.eclipse.jetty.util.resource.JarFileResource.list(JarFileResource.java:261)
    at org.eclipse.jetty.util.resource.ResourceCollection.list(ResourceCollection.java:421)
    at org.eclipse.jetty.util.resource.Resource.getListHTML(Resource.java:509)
    at org.eclipse.jetty.servlet.DefaultServlet.sendDirectory(DefaultServlet.java:741)
    at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:564)

When I run it from maven plugin (7.x) with jetty:run or jetty:run-war then I do not get any error.
What's more, accessing root path of web context gives that "zip file closed" error only when running on standalone jetty, but no such error when running from maven pluging, then is those directory view.

My web.xml:

   <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

pom.xml:

  ....
  <dependencies>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.3</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.3</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
</dependencies>
....
<plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>7.5.1.v20110908</version>

        <configuration>
            <scanIntervalSeconds>10</scanIntervalSeconds>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>com.sun.faces</groupId>
                <artifactId>jsf-api</artifactId>
                <version>2.1.3</version>
            </dependency>
            <dependency>
                <groupId>com.sun.faces</groupId>
                <artifactId>jsf-impl</artifactId>
                <version>2.1.3</version>
            </dependency>                    
        </dependencies>
    </plugin>   

Any idea what could it be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬﹪忆之殇 2024-12-16 14:36:13

问题已在jetty-7.6.0.RC2中修复。该错误是由 JVM 缓存 jar url 连接流引起的。

根据错误报告,您还需要将以下内容添加到 jetty.xml 中:

 <Set class="org.eclipse.jetty.util.resource.Resource" name="defaultUseCaches">false</Set>

This issue has been fixed in jetty-7.6.0.RC2. The bug is caused by the JVM caching jar url connection streams.

According to the bug report, you will need to also add the following to the jetty.xml:

 <Set class="org.eclipse.jetty.util.resource.Resource" name="defaultUseCaches">false</Set>
夜访吸血鬼 2024-12-16 14:36:13

Jetty 在 WEB-INF/lib 中的 jar 文件中查找您的资源。当它搜索 jsf-impl.jar 时,它会以某种方式关闭,可能是通过 JSF 请求关闭的。也许 jsf 会进行自己的资源处理并扰乱文件本身。

不管怎样,解决方案似乎是将 jsf jar 从 war 文件中移出。将你的jsf依赖范围设置为provided,这样maven就不会将它们打包到war文件中,并将它们放在服务器上,可能在jetty独立的lib文件夹中。

Jetty looks for your resources in the jar files in WEB-INF/lib. When it searches jsf-impl.jar it is somehow closed, probably by a JSF request. Perhaps jsf does its own resource handling and messes about with the files itself.

Anyway, the solution seems to be to move the jsf jars out of the war-file. Set your jsf dependency scope to provided so maven does not package them in the war file, and get them on the server, probably in the lib folder in jetty standalone.

冷月断魂刀 2024-12-16 14:36:13

我遇到了同样的问题,并设法通过转到 etc\webdefault.xml 并将此参数更改为 false 来解决它:

<init-param>
  <param-name>gzip</param-name>
  <param-value>true</param-value>
</init-param>

I had the same issue and managed to solve it by going to etc\webdefault.xml and changing this param to false:

<init-param>
  <param-name>gzip</param-name>
  <param-value>true</param-value>
</init-param>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文