The solution to the problem that the changed css, js and other static files cannot be saved after the maven environment in Eclipse is started with jetty

[Problem phenomenon]:

     Use Maven + Eclipse + Jetty for J2EE development, but there is a problem that after the static files such as css and js are changed, saving in eclipse will fail. The error message given by eclipse is that the file is locked, which forces Jetty to be restarted every time. , which is very inconvenient for development.

 

【Cause Analysis】:

    Jetty uses memory-mapped files to cache static files, including js and css files.

    Under Windows, using memory mapped files will cause the file to be locked, so js or css files cannot be edited in the editor when Jetty starts.

 

【solution】:

 

      Change the default configuration of Jetty, do not use memory-mapped files for caching.

 step:

     1. Find webdefault.xml and find the jetty plugin in the local repository. Take version 6.1.26 as an example, jetty-6.1.26.jar is in $maven_repo$/org/mortbay/jetty/jetty/6.1.26/jetty-6.1 .26.jar, the webdefault.xml file is under the package org\mortbay\jetty\webapp.

   Its path in the jar file is org/mortbay/jetty/webapp/webdefault.xml

 

  2. Find the useFileMappedBuffer parameter and set the value to false
    <init-param>
        <param-name>useFileMappedBufferparam-name>
        <param-value>false<param-value>
    init-param>

  3. In pom.xml, set jetty Use the updated webdefault.xml file

    <groupId>org.mortbay.jettygroupId>
    <artifactId>maven-jetty-plugin<artifactId>
    <version>6.1.26</version>
    <configuration>
        ...
        <webAppConfig>
           <defaultsDescriptor> src/test/resources/webdefault.xml</defaultsDescriptor>
        </webAppConfig>
    <configuration>

  You're done!

 

 

Donor sharer

          I didn't like programming before, but now I am an IT fan obsessed with programming. I would like to share some things I have sorted out and optimized here, hoping to help IT fans, with joy and sweat, and at the same time I also hope that everyone can support it. Of course, if you have money to support a money field (support Alipay and WeChat donations, join the it data center buckle group), but have no money to support a personal field, with your support, we will be more motivated and do better, thank you Ladies and gentlemen.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326466280&siteId=291194637