日期:2014-05-17  浏览次数:20557 次

(zz)jetty 运行时如何修改css html等文件
原因是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>

jetty7:
<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