Jetty( Files locked on Windows )转http://docs.codehaus.org/display/JETTY/Files+locked+on+Windows

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Skip to end of metadata Go to start of metadata

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 causes 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 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>
  <param-name>useFileMappedBuffer</param-name>
  <param-value>true</param-value> <!-- change to false -->
</init-param>

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

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

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"  class="org.mortbay.jetty.webapp.WebAppContext">
  <Set name="contextPath">/</Set>
  <Set name="war">./webapps/fredapp</Set>
  <Set name="defaultsDescriptor">/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.mortbay.jetty.webapp.WebAppContext">
  <Set name="contextPath">/</Set>
  <Set name="war">./webapps/fredapp</Set>
  <Set name="copyWebDir">true</Set>
  .
  .
 </New>

It seems one 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>

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

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值