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

使用mvn jetty:run web开发时,经常会遇到无法修改js文件问题,一修改就会报错: 

Java代码   收藏代码
  1. Could not write file:index.css.  
  2. index.css (请求的操作无法在使用用户映射区域打开的文件上执行。)  


Java代码   收藏代码
  1. Cannot save index.css.  
  2. The file was renamed to index.css___jb_old___.  
  3. Your changes were written to index.css___jb_bak___.  
  4. can not save files  
  5. following errors occurred on attempt to save files  


参考文档  
jetty 默认开启了 useFileMappedBuffer,在 jetty 运行期间,页面所使用的静态文件(如 css 文件等)不允许修改。如果你尝试去修改它 
们,保存的时候就会出现 Save could not be completed. 

解决办法: 
1、修改jar包 
2、修改启动参数 


对于第一种方法,修攺jar包的方式,参考文档里写的 

对于第二种方法,修改启动参数的方式,更加灵活,有多种修改法 
目前使用的是,在maven仓库里找到使用的jetty.jar,比如现在用的插件是 
Java代码   收藏代码
  1. <groupId>org.eclipse.jetty</groupId>  
  2. <artifactId>jetty-maven-plugin</artifactId>  
  3. <version>9.3.0.M2</version>  

对应的jar包是 
Java代码   收藏代码
  1. repositories\org\eclipse\jetty\jetty-webapp\9.3.0.M2\jetty-webapp-9.3.0.M2.jar  

解压出webdefault.xml,将useFileMappedBuffer改为false,文件另存为jettyCustom.xml 
Java代码   收藏代码
  1. //jettyCustom.xml  
  2.     <init-param>  
  3.       <param-name>useFileMappedBuffer</param-name>  
  4.       <param-value>false</param-value>  
  5.     </init-param>  


将该文件与pom.xml文件放在同一目录,修改maven配置,在所有的web上加 

<defaultsDescriptor>jettyCustom.xml</defaultsDescriptor> 

Java代码   收藏代码
  1. <!-- jetty 插件 -->  
  2.             <plugin>  
  3.                 <groupId>org.eclipse.jetty</groupId>  
  4.                 <artifactId>jetty-maven-plugin</artifactId>  
  5.                 <version>9.3.0.M2</version>  
  6.                 <configuration>  
  7.                     <webAppConfig>  
  8.                         <contextPath>/</contextPath>  
  9. //对当前web配置  jettyCustom.xml             <defaultsDescriptor>jettyCustom.xml</defaultsDescriptor>  
  10.                     </webAppConfig>  
  11.                     <scanIntervalSeconds>0</scanIntervalSeconds>  
  12.                     <httpConnector>  
  13.                        <port>8080</port>  
  14.                    </httpConnector>  
  15.   
  16. //加载多个web,每个web都需要配置jettyCustom.xml  
  17.                    <contextHandlers>  
  18.                       <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">  
  19.                             <resourceBase>E:\\workspace\\myweb\\webroot</resourceBase>  
  20.                         <contextPath>/myweb</contextPath>  
  21.                 <defaultsDescriptor>jettyCustom.xml</defaultsDescriptor>  
  22.                       </contextHandler>  
  23.                 </contextHandlers>  
  24.   
  25.                 </configuration>  
  26.             </plugin>  


再次启动后,js和css就没有缓存了 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值