Gradle Configure jetty to implement thermal deployment of static resources

Source: Internet
Author: User
Tags time interval


With Gradle we can easily use the built-in jetty to start our web program and debug locally. However, in the process of using, I found a few problems, resulting in the efficiency of local debugging is greatly affected.

If you use Gradle Jettyrun to start the jetty server, the static resources (jsp,html,javascript files) in the project are locked, resulting in the inability to modify these static resources in real time.

Since it is not possible to modify these static resources in real time, it means that we have to make a small change to stop jetty server, then modify and then restart Jetty Server, so waste a lot of time back and forth, especially when the front page changes, each adjustment of a parameter will need to restart jetty.

Since I used Maven before, jetty in Maven can show hot deployment. This means that if a static file is changed, the jetty can load and display in real time. It should not be difficult to achieve this in gradle, it took some time to get it done. the first thing to do is to fix the file lock.

Files are locked because jetty maps these files in memory by default when using Windows systems, and Windows locks memory-mapped files. The workaround is to modify the configuration of the jetty so that it sets the Usefilemappedbuffer flag bit to False when starting the server.

There are two ways to set up a method, one is to modify the Usefilemappdbuffer flag bit in the Webdefault.xml file. The Webdefault.xml file is a configuration file for the Jetty startup service, and the Web-inf/web.xml file its first in the project is loaded. This file is available by default in the jetty package, which can be extracted, saved in the project root directory, and modified by the Usefilemappedbuffer node.

1
2
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>

A reference to this file is then added to the Build.gradle.

1
2
3
[Jettyrun, Jettyrunwar,jettystop]*.with {
  webdefaultxml = file ("${rootdir}/webdefault.xml")
}

The second method is to modify the Web-inf/web.xml file in the project to include the node in it.

1
2
3
4
5
6
7
8
9
<servlet>
    <!--Override init parameter to avoid nasty--
    <!--file Locking issue on WINDOWS.
     -->
    <servlet-name>default</servlet-name>
        <init-param>
            <param-name> usefilemappedbuffer</param-name>
            <param-value>false</param-value>
        </init-param >
</servlet>
solve the problem of hot deploy of jetty.

This is relatively simple, Gradle jetty plug-in has two properties, one is the reload property, need to be set to automatic. Another property is Scanintervalseconds, which specifies the time interval for the jetty scan file to change, by default, 0, in seconds. Add the settings to the Build.gradle.

1
2
3
4
Jettyrun {
  reload = "Automatic"
  scanintervalseconds = 1
}

To live. Next Run Gradle Jettyrun, after the service starts up, if you modify a static resource, just press Ctrl+r to refresh the page to reload the resource.


From: http://www.huangbowen.net/blog/2013/09/04/hot-deploy-for-jetty-gradle-plugin/?utm_source=tuicool&utm_ Medium=referral

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.