There are cases, when restart of the web-app on every resource change is not optimal (too slow). Specifically for such cases Gretty implements "fast reload" feature. Fast reload handles changes in src/main/webapp directory: whenever some files within this directory are changed, these files are copied into running web-app without web-app restart.

Gretty version 1.1.4+ supports inplaceMode property (see below), allowing to accelerate resource reloads by serving files directly from src/main/webapp (thus avoiding file copy on change).

You can configure fastReload feature by adjusting the gretty configuration properties:

  • fastReload boolean.

    • When set to false, fast reload feature is disabled. Effect: any resource changes will cause full restart of web-app (as far as scanInterval is set to non-zero, see Hot deployment).

    • When set to true (the default), webAppDir folder (which is typically src/main/webapp) is set as being fast-reloaded. That means: whenever some files within webAppDir are changed, these files are copied into running web-app without web-app restart.

  • fastReload function(String) or function(java.io.File). The specified directory or file is added to fast-reloaded resources.

  • fastReload function(Map). Map may contain the following properties:

    • "baseDir" is required and should have type String or java.io.File. If baseDir represents a relative path, gretty tries to find corresponding existing folder in the following directories:

      • "$project.projectDir"

      • "$project.webAppDir"

      • "$project.buildDir/classes/main"

      • "$project.buildDir/resources/main" each resolved subfolder within these folders is added to fast reload.

    • "pattern" is optional and should have type String or java.util.regex.Pattern.

      • If "pattern" is not specified, then all files within baseDir are fast-reloaded.

      • If "pattern" is specified, then only the files, whose relative (to baseDir) path satisfies "pattern", are fast-reloaded, other files are full-reloaded.

    • "excludesPattern" is optional and should have type String or java.util.regex.Pattern.

      • If "excludesPattern" is not specified, then "pattern" fully defines which files are fast-reloaded.

      • If "excludesPattern" is specified, then those files whose relative (to baseDir) path satisfies "excludesPattern", are not fast-reloaded. "excludesPattern" is always applied after "pattern".

  • inplaceMode can be "soft" or "hard" (default "soft"). When "hard", the web-server serves the resources (of the given web-app) directly from src/main/webapp. When "soft", the web-server serves the resources (of the given web-app) from build/inplaceWebapp.

Gretty fast reload assumes the following defaults:

  • fastReload property is set to true.

  • Fast reload always excludes the following files: *.jar, *.class, web.xml, web-fragment.xml, jetty.xml, jetty-env.xml, tomcat-users.xml, WEB-INF/lib/**, WEB-INF/classes/**. That means: when these files are changed, web-app is fully restarted.

You can add more than one fastReload specification. In such case all specified directories are fast-reloaded.

Tip
Gretty supports fast reload only on non-test gradle tasks. Any test tasks (including integration test tasks) run without fast reload. The generated products also run without fast reload.