jetty锁定文件

jetty在运行是会对静态文件锁定,导致无法修改

jetty官方给出说明:

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 lock, so that you cannot update or replace the file. Effectively this means that 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 jetty distribution under the etc/ directory or in the jetty-webapp-${version}.jar artifact at org/eclipse/jetty/webapp/webdefault.xml. Edit the file in the distribution or extract it to a convenient disk location and edit it to change useFileMappedBuffer to false. The easiest option is to simply edit the default file contained in the jetty distribution itself.

<init-param>

   <param-name>useFileMappedBuffer</param-name>

   <param-value>true</param-value> <!-- change to false -->

 </init-param>

Make sure to apply your custom webdefault.xml file to all of your webapps. You can do that by changing the configuration of the Deployment Manager in etc/jetty-deploy.xml.


当jetty已maven嵌入式的形式运行程序时,修改方法:

1、maven本地仓库.m2->\org\eclipse\jetty\jetty-webapp\下找到对于版本的jetty-webapp.jar

2、修改包中文件org\eclipse\jetty\webapp\webdefault.xml内容:

<init-param>

   <param-name>useFileMappedBuffer</param-name>

   <param-value>false</param-value> <!-- change to false -->

 </init-param>

   <plugin>

        <groupId>org.mortbay.jetty</groupId>

        <artifactId>maven-jetty-plugin</artifactId>

        <version>6.1.10</version>

        <configuration>

    <webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml> 

   </configuration> 

  </plugin>


参考:

http://www.eclipse.org/jetty/documentation/current/troubleshooting-locked-files-on-windows.html

http://stamen.iteye.com/blog/1933452


你可能感兴趣的:(jetty)