I have a Spring framework
project with the following three files in src/main/webapp/WEB-INF
:
project.propterties
project-servlet.xml
project-security.xml
I am trying to use maven profiles
as follows to 'inject' the above mentioned files in the case of a prod
build:
<profile>
<id>prod-build</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete
file="${project.build.directory}/${project.build.finalName}/WEB-INF/project.properties" />
<copy file="src/main/config/prod/project.properties"
tofile="${project.build.directory}/${project.build.finalName}/WEB-INF/project.properties" />
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources/prod</directory>
</resource>
</resources>
</build>
</profile>
The problem is by the time maven-antrun-plugin
gets a chance to run, the war
has already been packaged. The ant <target>
does run and makes appropriate changes, but too late.
The command line:
$ mvn -Pprod-build clean install
mvn output:
[INFO] --- maven-antrun-plugin:1.7:run (default) @ FocusMVN ---
[INFO] Executing tasks
main:
[copy] Copying 1 file to J:\work\workspace\FocusMVN\target\myproject\WEB-INF
[INFO] Executed tasks
[INFO]
[INFO] --- maven-war-plugin:2.3:war (default-war) @ FocusMVN ---
[INFO] Packaging webapp
[INFO] Assembling webapp [FocusMVN] in [J:\work\workspace\FocusMVN\target\myproject]
[INFO] Processing war project
[INFO] Copying webapp resources [J:\work\workspace\FocusMVN\src\main\webapp]
[INFO] Webapp assembled in [3198 msecs]
[INFO] Building war: J:\work\workspace\FocusMVN\target\myproject.war
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ FocusMVN ---
[INFO] Installing J:\work\workspace\FocusMVN\target\myproject.war to C:\Users\mansoork\.m2\repository\ca\utoronto\med\dc\FocusMVN\0.0.1-SNAPSHOT\FocusMVN-0.0.1-SNAPSHOT.war
[INFO] Installing J:\work\workspace\FocusMVN\pom.xml to C:\Users\mansoork\.m2\repository\ca\utoronto\med\dc\FocusMVN\0.0.1-SNAPSHOT\FocusMVN-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Any pointers will be greatly appreciated.
Did you note this line
[INFO] Copying webapp resources [J:\work\workspace\FocusMVN\src\main\webapp]
What's going on ?
The maven-war-plugin
copy the content of src/main/webapp
(which contains your dev project.properties
) to the war. And while doing this it replace the one just copied by the ant task.
What you can try is to exclude the project.properties
from the fileset copied by the maven-war-plugin (since it was already copied by your ant task.)
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceExcludes>WEB-INF/project.propterties</warSourceExcludes>
</configuration>
</plugin>