Filtering Maven Files in WEB-INF

I am trying to add some filtering to the application context file, which is located in the WEB-INF directory.

I have a file to filter out (xmlgateway-context.xml) in the / src / main / resources folder.

I have properties files (config-e05.properties) in the src / main / filters folder

And my POM is configured as follows:

<!-- environment profiles --> <profiles> <profile> <id>e04</id> <properties> <targetenv>e04</targetenv> </properties> </profile> <profile> <id>e05</id> <properties> <targetenv>e05</targetenv> </properties> </profile> </profiles> <!-- build settings (filtering) --> <build> <filters> <filter>src/main/filters/config-${targetenv}.properties</filter> </filters> <resources> <resource> <targetPath>WEB-INF</targetPath> <filtering>true</filtering> <directory>src/main/resources</directory> </resource> </resources> </build> 

This will be correctly installed by mvn, but when I open the output file of the war, I expected the xmlgateway-context.xml file to be in the / WEB -INF directory, but it falls into the folder / WEB-INF / classes / WEB-INF.

How can I get this file in the right place.

Alternatively, I can put the application context in another place and refer to it there.

+41
java maven-2
Nov 23 '09 at 10:48
source share
4 answers
 <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 value to your pom.xml. EDIT: Only to explain what the above conf does. With this addition, mvn is going to filter the files in src/main/webapp/WEB-INF and, in particular, filter the included xmlgateway-context.xml files, and after filtering it will push the files in the WEB-INF folder (this is what the tag says target ).

Refresh if something is unclear.

+83
Nov 23 '09 at 10:58
source share

You should configure filtering using the maven war : checkout plugin for these examples .

+4
Nov 23 '09 at 10:56
source share

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> 
0
Jan 10 '17 at 12:31 on
source share

Place the xmlgateway-context.xml file in src / main / webapp / WEB-INF and configure as follows:

 <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> 
-2
Nov 23 '09 at 11:02
source share



All Articles