起因为maven项目配置jetty-maven-plugin插件,以jetty:run方式运行,会出现静态文件保存不了的问题。原因是jetty内存映射文件来缓存静态文件. 解决方法是将jetty内存映射参数取消掉.解决找webdefault.xml文件在下面路径找到webdefault.xml文件
C:\Users\Administrator\.m2\repository\org\eclipse\jetty\jetty-webapp\9.2.6.v20141205
如果安装了jetty服务器,在它的etc目录下也可以取到webdefault.xml文件useFileMappedBuffer参数值改为falsewebdefault.xml配置
<init-param> <param-name>useFileMappedBuffer</param-name> <param-value>false</param-value></init-param>
新增defaultsDescriptor配置项
<plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.2.6.v20141205</version> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> <webAppSourceDirectory>${basedir}/WebRoot</webAppSourceDirectory> <webApp> <contextPath>/</contextPath> <war>${project.build.directory}/${project.build.finalName}.war</war> <!-- jetty9.2.6的defaultsDescriptor在<webApp>里,早期版本在<configuration>或者<webAppConfig>里 --> <defaultsDescriptor>${basedir}/WebRoot/resources/webdefault.xml</defaultsDescriptor> </webApp> </configuration></plugin>
webdefault.xml加载是否成功控制台输出如下,表示加载了webdefualt.xml
[INFO] Web defaults = .... /WebRoot/resources/webdefault.xml
感受上面方法虽然可以解决问题,但是很不好用. 如果jetty-maven-plugin能设计个开发模式设置,在易用性上会有更大提升.参考资料jetty-maven-plugin配置文档http://eclipse.org/jetty/documentation/current/jetty-maven-plugin.htmlmaven文档http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-maven-plugin/9.2.6.v20141205?? 漫过心际的孤独,早已蔚然成冰,而你是这个季节里最美的音符。