Jetty上的JSF2随机给出“关闭的zip文件",但从maven jetty插件运行时可以工作(jetty:run) [英] JSF2 on Jetty gives randomly 'zip file closed' but works when running from maven jetty plugin (jetty:run)

查看:101
本文介绍了Jetty上的JSF2随机给出“关闭的zip文件",但从maven jetty插件运行时可以工作(jetty:run)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

当我使用jetty:run或jetty:run-war从maven插件(7.x)运行它时,我没有得到任何错误. 而且,仅当在独立码头上运行时,访问Web上下文的根路径才会显示"zip文件已关闭"错误,而在通过maven插入运行时则不会出现此类错误,那么这些目录视图就是如此.

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.

我的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>   

有什么想法吗?

推荐答案

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

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.

无论如何,解决方案似乎是将jsf jar从战争文件中移出.将您的jsf依赖范围设置为提供,以使maven不会将它们打包在war文件中,而不会将它们放在服务器上,可能在独立码头的lib文件夹中.

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.

这篇关于Jetty上的JSF2随机给出“关闭的zip文件",但从maven jetty插件运行时可以工作(jetty:run)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆