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

来源:互联网 发布:2008年科比总决赛数据 编辑:程序博客网 时间:2024/05/20 09:10
使用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