maven jetty 热部署 Files are locked on Windows and can't be replaced

3 篇文章 0 订阅
3 篇文章 0 订阅

在windows操作系统用jetty maven plugin运行jetty:run命令,修改静态html等资源后不能保存,出现文件被锁问题。

原因:maven jetty plugin 的默认webdefault.xml中的default servlet的初始参数useFileMappedBuffer值为true。

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. See Sun bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154. This means that effectively you have to stop Jetty in order to update a file.

<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
    <init-param>
      <param-name>aliases</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>acceptRanges</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>dirAllowed</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>welcomeServlets</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>redirectWelcome</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>maxCacheSize</param-name>
      <param-value>256000000</param-value>
    </init-param>
    <init-param>
      <param-name>maxCachedFileSize</param-name>
      <param-value>200000000</param-value>
    </init-param>
    <init-param>
      <param-name>maxCachedFiles</param-name>
      <param-value>2048</param-value>
    </init-param>
    <init-param>
      <param-name>gzip</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>etags</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>useFileMappedBuffer</param-name>
      <param-value>true</param-value>
    </init-param>
    <!--
    <init-param>
      <param-name>resourceCache</param-name>
      <param-value>resourceCache</param-value>
    </init-param>
    -->
    <!--
    <init-param>
      <param-name>cacheControl</param-name>
      <param-value>max-age=3600,public</param-value>
    </init-param>
    -->
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

解决:

1.可以拷贝一份webdefault.xml到工程的resources目录修改参数useFileMappedBuffer为false。并在plugin的configuration配置如下参数

<plugin>
            ...
            <artifactId>jetty-maven-plugin</artifactId>
            <configuration>
                <webAppConfig>
                  ...
                  <defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
                </webAppConfig>
            </configuration>
</plugin>

2.

在web.xml 添加如下参数

jetty plugin groupId为org.eclipse.jetty 添加

<context-param>
    <param-name>org.eclipse.jetty.servlet.Default.useFileMappedBuffer</param-name>
    <param-value>false</param-value>
</context-param>
====================================================================================

jetty plugin groupId为org.mortbay.jetty 添加

<context-param>
    <param-name>org.mortbay.jetty.servlet.Default.useFileMappedBuffer</param-name>
    <param-value>false</param-value>
</context-param>

参考:

http://www.eclipse.org/jetty/documentation/current/troubleshooting-locked-files-on-windows.html
http://docs.codehaus.org/display/JETTY/Files+locked+on+Windows






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值