Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Jetty/Howto/Deal with Locked Windows Files

< Jetty‎ | Howto
Revision as of 17:08, 11 July 2011 by Boulay.intalio.com (Talk | contribs) (New page: {{Jetty Howto | introduction = (required) Jetty buffers static content for webapps such as html files, css files, images, etc. If you are using NIO connectors, Jetty uses memory-mapped fil...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)



Introduction

(required) Jetty buffers static content for webapps such as html files, css files, images, etc. If you are using NIO connectors, Jetty uses memory-mapped files to do this. The problem is that on Windows, memory mapping a file causes the file to be locked, so that you cannot update or replace the file. This means that effectively you have to stop Jetty to update a file.

Remedy

Jetty provides a configuration switch in the webdefault.xml file for the DefaultServlet that enables or disables the use of memory-mapped files. If you are running on Windows and are having file-locking problems, you should set this switch to disable memory-mapped file buffers.

The default webdefault.xml file is found in the lib/jetty.jar at org/mortbay/jetty/webapp/webdefault.xml. Extract it to a convenient disk location and edit it to change useFileMappedBuffer to false.

 
 <init-param></span>
   <param-name></span>useFileMappedBuffer</param-name></span>
   <param-value></span>true</param-value></span> <!-- change to false --></span></span>
 </init-param></span>

Then, ensure that you apply your custom webdefault.xml file to all of your webapps. You can do that by changing the configuration of the WebAppDeployer in etc/jetty.xml.

 
     <Call name="addLifeCycle"</span>></span>
       <Arg></span>
         <New class="org.mortbay.jetty.deployer.WebAppDeployer"</span>></span>
           <Set name="contexts"</span>></span><Ref id="Contexts"</span>/></span></Set></span>
           <Set name="webAppDir"</span>></span><SystemProperty name="jetty.home"</span> default="."</span>/></span>/webapps</Set></span>
           <Set name="parentLoaderPriority"</span>></span>false</Set></span>
           <Set name="extract"</span>></span>true</Set></span>
           <Set name="allowDuplicates"</span>></span>false</Set></span>
           <Set name="defaultsDescriptor"</span>></span>/home/fred/jetty/mywebdefaults.xml</Set></span> <!-- set to your customized defaults file --></span></span>
         </New></span>
       </Arg></span>
     </Call></span>

Alternatively, if you have individually configured your webapps with context xml files, you need to call the WebAppContext.setDefaultsDescriptor(String path) method:

 
 <New id="myWebAppContext"</span>  class="org.mortbay.jetty.webapp.WebAppContext"</span>></span>
   <Set name="contextPath"</span>></span>/</Set></span>
   <Set name="war"</span>></span>./webapps/fredapp</Set></span>
   <Set name="defaultsDescriptor"</span>></span>/home/fred/jetty/mywebdefaults.xml</Set></span>
   .
   .
  </New></span>

Alternate Remedy

You can force a WebAppContext to always copy a web app directory on deployment to avoid the file locking issue. Configure this in a context deployment file as follows:

 
 <New id="myWebAppContext"  class="org.mortbay.jetty.webapp.WebAppContext">
   <Set name="contextPath">/</Set>
   <Set name="war">./webapps/fredapp</Set>
   <Set name="copyWebDir">true</Set>
   .
   .
  </New>

You can also configure the default Jetty Servlet directly in the web.xml. For example:

 
 <web-app ...>
 ...
 <servlet>
     <servlet-name>default</servlet-name>
     <servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
     <init-param>
       <param-name>useFileMappedBuffer</param-name>
       <param-value>false</param-value>
     </init-param>
     <load-on-startup>0</load-on-startup>
   </servlet>
 ...
 </web-app>

This might completely redefine the default servlet configuration (not sure about that, if anyone can confirm). You could still simply extract the webdefault file as explained above, and copy-paste the complete default servlet definition in your web.xml, changing that useFileMappedBuffer parameter to false.







(optional) - categor(ies) to use for this page. If blank, will use the template name as a default category Example:

Copyright © Eclipse Foundation, Inc. All Rights Reserved.