Issue
I'm currently setting up a web project with maven 3.1.1 and maven war plugin 2.4 (http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html). In particular, I'm trying to copy and filter a resource with maven war plugin in a way that I've already done in the past and it worked. Here follows the relevant pom configuration:
WAR plugin configuration
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
...
<webResources>
<resource>
<directory>src/main/webapp/META-INF</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
</resource>
...
</configuration>
</plugin>
...
Activated profile definition:
...
<profiles>
<profile>
<id>dummyDev</id>
<build>
<filters>
<filter>filters/development.properties</filter>
</filters>
</build>
</profile>
...
META-INF/context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="${tomcat.context.reloadable}">
</Context>
And finally "development.properties":
tomcat.context.reloadable=true
The context.xml gets copied into the WAR, but not filtered. If I try to write directly the property in the profile it works (i.e. without referencing to properties file): it doesn't work only when I reference thep properties file. It seems that there's something wrong in reading the properties file. Moreover, after having "packaged", maven doesn't tell me in the console that the properties file wasn't found (so maven finds the file).
Finally I tried to achieve the work with maven war plugin version 2.1.1 (and version 2.3) and it works: I tried more times just changing the maven war plugin's version so I'm pretty sure that the problem is that.
Am I missing something? Is this a known bug of maven war plugin? Am I trying to reach the result (filtering that file) in the right way? Thanks.
Solution
Well, I searched over maven war plugin jira's and foud out that this is actually a bug, introduced in version 2.4 (more at https://issues.apache.org/jira/browse/MWAR-301).
For convenience i quote the work-around pointed out in the jira issue:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
...
<filters>
<filter>${project.basedir}/src/main/filters/my-filter.properties</filter>
</filters>
</configuration>
</plugin>
Tried it on my skin and it works.
Anyway i note that if you specify a properties source file in this position (and this is pom-level war plugin declaration, not profile level), this will be read always, i.e. for every build profile you're specifying. Unless you re-declare the war plugin for each build profile and in each profile specify a different set of properties files (a really bad solution, pointed out here only to say that's wrong-way and for the sake of completeness, obviously IMHO), this solution is limited only to the case in which the given properties file must be always read no matter what build profile has been specified.
Answered By - reallynice
Answer Checked By - Mildred Charles (JavaFixing Admin)