使用mvn jetty:run web开发时,经常会遇到无法修改js文件问题,一修改就会报错:
Could not write file:index.css.
index.css (请求的操作无法在使用用户映射区域打开的文件上执行。)
Cannot save index.css.
The file was renamed to index.css___jb_old___.
Your changes were written to index.css___jb_bak___.
can not save files
following errors occurred on attempt to save files
参考文档
jetty 默认开启了 useFileMappedBuffer,在 jetty 运行期间,页面所使用的静态文件(如 css 文件等)不允许修改。如果你尝试去修改它
们,保存的时候就会出现 Save could not be completed.
解决办法:
1、修改jar包
2、修改启动参数
对于第一种方法,修攺jar包的方式,参考文档里写的
对于第二种方法,修改启动参数的方式,更加灵活,有多种修改法
目前使用的是,在maven仓库里找到使用的jetty.jar,比如现在用的插件是
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.0.M2</version>
对应的jar包是
repositories\org\eclipse\jetty\jetty-webapp\9.3.0.M2\jetty-webapp-9.3.0.M2.jar
解压出webdefault.xml,将useFileMappedBuffer改为false,文件另存为jettyCustom.xml
//jettyCustom.xml
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>
</init-param>
将该文件与pom.xml文件放在同一目录,修改maven配置,在所有的web上加
<defaultsDescriptor>jettyCustom.xml</defaultsDescriptor>
<!-- jetty 插件 -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.0.M2</version>
<configuration>
<webAppConfig>
<contextPath>/</contextPath>
//对当前web配置 jettyCustom.xml <defaultsDescriptor>jettyCustom.xml</defaultsDescriptor>
</webAppConfig>
<scanIntervalSeconds>0</scanIntervalSeconds>
<httpConnector>
<port>8080</port>
</httpConnector>
//加载多个web,每个web都需要配置jettyCustom.xml
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<resourceBase>E:\\workspace\\myweb\\webroot</resourceBase>
<contextPath>/myweb</contextPath>
<defaultsDescriptor>jettyCustom.xml</defaultsDescriptor>
</contextHandler>
</contextHandlers>
</configuration>
</plugin>
再次启动后,js和css就没有缓存了