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>开发者_JAVA技巧
<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?
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>
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.
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>
精彩评论