I am trying to add some filtering to the application context file, which resides in the WEB-INF directory.
I have the file which is to be filtered (xmlgateway-context.
With filteringDeploymentDescriptors set to true
<build>
<finalName>web-project-name</finalName>
<filters>
<filter>src/main/resources/app.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
</plugins>
</build>
you should configure filtering via the maven war plugin: checkout these examples.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/xmlgateway-context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
Add the above to your pom.xml.
EDIT: Just to explain what the above conf is doing. With this added, mvn is going to filter files under src/main/webapp/WEB-INF
and in particular filter the included files xmlgateway-context.xml
and after filtering it is going to push the files in WEB-INF
folder (thats what the target
tag is saying).
Update if something is not clear.
Put the file xmlgateway-context.xml in src/main/webapp/WEB-INF and configure like this:
<build>
<filters>
<filter>src/main/filters/config-${targetenv}.properties</filter>
</filters>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp/WEB-INF</directory>
</resource>
</resources>
</build>