解决Maven Jetty Plugin在Windows下的“文件锁定”问题

使用Maven进行Java的web开发,Jetty Plugin是必不可缺的插件,可以极大的提到开发效率。但在Windows环境下会遇到静态文件(html、css、js)被锁定、无法即时更新的问题。要想更新这些文件,只能先停掉Jetty,保存修改,再启动Jetty,非常不方便。
解决办法是这样的:
1、从jetty.jar中解出webdefault.xml(位于org.mortbay.jetty.webapp包下)这个文件,把这个useFileMappedBuffer参数设为false

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

2、把修改后的webdefault.xml文件跟pom.xml放在一起
3、修改pom.xml里的Jetty Plugin的配置,加入webdefault.xml

...
<plugin>
   <groupId>org.mortbay.jetty</groupId>
   <artifactId>maven-jetty-plugin</artifactId>
   <version>6.1.7</version>
   <configuration>
     <contextPath>/</contextPath>
     <webDefaultXml>webdefault.xml</webDefaultXml>
     ...
    </configuration>
    ...
</plugin>
...

One thought on “解决Maven Jetty Plugin在Windows下的“文件锁定”问题

Leave a Reply

Your email address will not be published. Required fields are marked *

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.
For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>