Difference between revisions of "Jetty/Zip Exceptions Reading Jar or War Files"

From Eclipsepedia

Jump to: navigation, search
m
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{Jetty Howto
 
{{Jetty Howto
 
| introduction =
 
| introduction =
 +
 +
{{Jetty Redirect|http://www.eclipse.org/jetty/documentation/current/troubleshooting.html#troubleshooting-zip-exceptions}}
  
 
A Zip exception occurs when Jetty rereads a Jar or WAR file.
 
A Zip exception occurs when Jetty rereads a Jar or WAR file.
Line 12: Line 14:
 
* Deploy unpacked classes in the <tt>WEB-INF/classes</tt> directory rather than as a Jar file under <tt>WEB-INF/lib</tt>.
 
* Deploy unpacked classes in the <tt>WEB-INF/classes</tt> directory rather than as a Jar file under <tt>WEB-INF/lib</tt>.
 
* Deploy all WAR and Jar files with a version number in their filename or path. If the code changes, a new version number applies, avoiding the cache problem.
 
* Deploy all WAR and Jar files with a version number in their filename or path. If the code changes, a new version number applies, avoiding the cache problem.
* Deploy a packed WAR file with the [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setExtractWAR(boolean) setExtractWAR] option set to true. This causes the WAR to be extracted to a [[Jetty/Reference/Temporary_Directories|temporary directory]] and thus to a new location. This might not be sufficient if you want to hot-replace and reextract the WAR, so you might also need to use [http://download.eclipse.org/jetty/stable7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebInf(boolean) WebAppContext.setCopyWebInf(true)], which (re)copies just the WEB-INF directory to a different location.
+
* Deploy a packed WAR file with the [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setExtractWAR(boolean) setExtractWAR] option set to true. This causes the WAR to be extracted to a [[Jetty/Reference/Temporary_Directories|temporary directory]] and thus to a new location. This might not be sufficient if you want to hot-replace and reextract the WAR, so you might also need to use [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebInf(boolean) WebAppContext.setCopyWebInf(true)], which (re)copies just the WEB-INF directory to a different location.
 
* Deploy an unpacked WAR file with the [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebDir(boolean) setCopyWebDir] option set to true. This causes the directory to be extracted to a new location.  
 
* Deploy an unpacked WAR file with the [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebDir(boolean) setCopyWebDir] option set to true. This causes the directory to be extracted to a new location.  
  
 
Be aware that any of the techniques listed above that involve copying part or all of the webapp will probably not avoid the zip file problem if you are using a [[Jetty/Reference/Temporary_Directories|work directory]] (which avoids re-extraction on start/stop of a context or container).
 
Be aware that any of the techniques listed above that involve copying part or all of the webapp will probably not avoid the zip file problem if you are using a [[Jetty/Reference/Temporary_Directories|work directory]] (which avoids re-extraction on start/stop of a context or container).
  
If you have problems with [[/Jetty/Howto/Deal_with_Locked_Windows_Files|Windows file-locking]] preventing static file editing (such as JSP or HTML), use the [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebDir(boolean) WebAppContext.setCopyWebDir(true)] option.
+
If you have problems with [[Jetty/Howto/Deal_with_Locked_Windows_Files|Windows file-locking]] preventing static file editing (such as JSP or HTML), use the [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebDir(boolean) WebAppContext.setCopyWebDir(true)] option.
  
 
}}
 
}}

Latest revision as of 16:01, 23 April 2013



[edit] Introduction


A Zip exception occurs when Jetty rereads a Jar or WAR file.

The JVM maintains a cache of zip file indexes, and does not support hot replacement of zip files. Thus if you redeploy a web application using the same WAR or Jar files, exceptions occur when Jetty rereads the jars. See Oracle Bug 4774421 for more information.

Remedy

The remedy is to avoid hot replacing Jar or WAR files, which can be difficult if you are using the hot Context Provider. You can use the following techniques to reduce exposure to this issue:

  • Deploy unpacked classes in the WEB-INF/classes directory rather than as a Jar file under WEB-INF/lib.
  • Deploy all WAR and Jar files with a version number in their filename or path. If the code changes, a new version number applies, avoiding the cache problem.
  • Deploy a packed WAR file with the setExtractWAR option set to true. This causes the WAR to be extracted to a temporary directory and thus to a new location. This might not be sufficient if you want to hot-replace and reextract the WAR, so you might also need to use WebAppContext.setCopyWebInf(true), which (re)copies just the WEB-INF directory to a different location.
  • Deploy an unpacked WAR file with the setCopyWebDir option set to true. This causes the directory to be extracted to a new location.

Be aware that any of the techniques listed above that involve copying part or all of the webapp will probably not avoid the zip file problem if you are using a work directory (which avoids re-extraction on start/stop of a context or container).

If you have problems with Windows file-locking preventing static file editing (such as JSP or HTML), use the WebAppContext.setCopyWebDir(true) option.