使用过Maven的朋友都知道,使用Maven+Jetty进行JavaWeb开发,可以很大程度上提高开发效率。但在开发环境中会遇到静态文件(html、css、js)被锁定、无法即时更新的问题。要想变更此类静态文件,只能先停掉Jetty,保存修改,再启动Jetty,非常不方便。
解决方式:
1.找到jetty/wabapp下的webdefault.xml文件(或在jetty的安装目录jetty/etc),拷贝到任一地方
2.修改useFileMappedBuffer值为false
3.在pom.xml中指定使用修改过的webdefault.xml (如下)
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.1.6.v20100715</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/</contextPath>
<defaultsDescriptor>readme/build/webdefault.xml</defaultsDescriptor>
</webAppConfig>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>80</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>