Need to update 'web.xml' within WAR file


(Vance A.) #1

Using: Gradle 4.1 under Windows 7

I’m working on a Gradle build script for a Web-app, and I need to update the ‘web.xml’ file with values from a properties-file. Is there a way to do this?


(James Justinic) #2

The war task supports a filter (such as ReplaceTokens) and filesMatching so you don’t have to run this on every single file. Additionally you should add the properties file as an input if it is otherwise not a part of the source for your WAR file so that it is regenerated if these properties change.

war {
    ext.webXmlProperties = 'path/to/webXml.properties'
    inputs.file webXmlProperties
    filesMatching('WEB-INF/web.xml') {
       filter org.apache.tools.ant.filters.ReplaceTokens, propertiesResource: ant.file(file: webXmlProperties)
    }
}