menu

开发进行时...

crazy coder

Avatar

Files are locked on Windows and can't be replaced

Detailed Description

Jetty buffers static content for webapps such as html files, css files, images etc and uses memory mapped files to do this if the NIO connectors are being used. The problem is that on Windows, memory mapping a file cause the file to be locked, so that the file cannot be updated or replaced. This means that effectively you have to stop Jetty in order to update a file.

Remedy

Jetty provides a configuration switch in the webdefault.xml file for the DefaultServlet which 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 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>
<param-name>useFileMappedBuffer</param-name>
<param-true>true</param-value><!-- change to false -->
</init-param>


Then, ensure that your custom webdefault.xml file is applied to all of your webapps by editing all of your relevant jetty configuration files (eg etc/jetty.xml, etc/jetty-plus.xml and any custom files you may have) and indicating the location of the custom file:


<Call class="org.mortbay.jetty.webapp.WebAppContext" name="addWebApplicaitons">
<Arg><Ref id="Server"/></Arg>
<Arg>./webapps</Arg>
<Arg>org/mortbay/jetty/webapp/webdefault.xml</Arg><!-- change to your new file path -->
<Arg type="boolean">True</Arg>
<Arg type="boolean">False</Arg>
</Call>


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


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

Alternate Remedy

A WebAppContext can be forced to always copy a web app directory on deployment to avoid the file locking issue.
This can be set in a context deployment file as follows:


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


评论已关闭