mvn jetty:run无法修改js css文件问题的解决

本文介绍了解决Jetty服务器中因默认开启useFileMappedBuffer而导致的无法修改静态文件(如CSS和JS文件)的问题。提供了两种解决方案:修改jar包和通过调整启动参数来禁用缓存。
使用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


[url=http://www.blogjava.net/fancydeepin/archive/2015/06/23/maven-jetty-plugin.html]参考文档[/url]
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就没有缓存了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值