Web resources filtering with Maven war plugin does not work in Eclipse with m2e

I had a similar problem with filtering the web.xml. I solved the problem by reimporting the whole project in eclipse.

The reason was a corrupt /.settings/org.eclipse.wst.common.component file. In this file the order of the files copied to the local web servers deploy directory is defined. For example:

<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="liquidvote-rest">
    <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
    <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
    <property name="context-root" value="myapp"/>
    <property name="java-output-path" value="/myapp/target/classes"/>
  </wb-module>
</project-modules>

If the web.xml or application.xml exists in several directories it will be taken from the first directory found. Therefore its important that

    <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>

is the first entry.

You will find more informations at http://wiki.eclipse.org/M2E-WTP_FAQ in the section "What is this web resources folder?"


Well, finally I got it.

First of all, I did what khmarbaise pointed out. I moved applicationContext.xml to the resources folder. War plugin webResources are meant to work with external resources, and filtering a file in the destination folder itself was not the best practice. I updated the POM to reflect the new configuration

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

and

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <webResources>
                    <resource>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF/context</targetPath>
                        <directory>src/main/resources/WEB-INF/context</directory>
                        <includes>
                            <include>applicationContext.xml</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

So, half of the credit to him. But that's was not enough, it still didn't work. I realized that Maven/m2e was indeed filtering my file, but it didn't get my defined properties files. After some testing I found out that m2e is ignoring the activeByDefault option in the profiles activation section.

So, I added my default profile to the project Maven configuration and then it worked

enter image description here