原因是Jetty会使用内存映射文件来缓存静态文件,其中包括js、css文件。在Windows下面,使用内存映射文件会导致文件被锁定。解决方案是不使用内存映射文件来做缓存。步骤如下:
1)在所使用Jetty版本的jar中找到webdefault.xml,把它拷贝到项目中,比如src/main/resources/webdefault.xml 。
对
jetty6 ,jar文件在$maven_repo$/org/mortbay/jetty/jetty/6.x/jetty-6.x.jar,webdefault.xml文件在包org\mortbay\jetty\webapp里;
对
jetty7 ,jar文件在$maven_repo$/org/eclipse/jetty/jetty-webapp/7.x/jetty-webapp-7.x.jar\,webdefault.xml文件在包org\eclipse\jetty\webapp里。
2)找到
webdefault.xml文件里的
useFileMappedBuffer参数,把值设成false。
3)在pom.xml中,设置jetty使用更新过的webdefault.xml文件。
jetty6:
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.x</version>
<configuration>
<webDefaultXml> src/main/resources/webdefault.xml </webDefaultXml>
</configuration>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.x</version>
<configuration>
<webDefaultXml> src/main/resources/webdefault.xml </webDefaultXml>
</configuration>
jetty7:
这样在运行时就可以修改js、css等文件了 。
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.x</version>
<configuration>
<webAppConfig>
<defaultsDescriptor>
src/main/resources/webdefault.xml </defaultsDescriptor>
</webAppConfig>
</configuration>
这样在运行时就可以修改js、css等文件了 。
修改后eclipse控制台会输出如下信息:
[INFO] Web defaults = src/main/resources/webdefault.xml