title: Maven profiles: maven-antrun-plugin & maven-war-plugin interaction
body: <p>I have a <code>Spring framework</code> project with the following three files in <code>src/main/webapp/WEB-INF</code>:</p>
  
  <pre><code>project.propterties
  project-servlet.xml
  project-security.xml
  </code></pre>
  
  <p>I am trying to use <code>maven profiles</code> as follows to 'inject' the above mentioned files in the case of a <code>prod</code> build:</p>
  
  <pre><code>        &lt;profile&gt;
          &lt;id&gt;prod-build&lt;/id&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
                      &lt;version&gt;1.7&lt;/version&gt;
                      &lt;executions&gt;
                          &lt;execution&gt;
                              &lt;phase&gt;prepare-package&lt;/phase&gt;
                              &lt;goals&gt;
                                  &lt;goal&gt;run&lt;/goal&gt;
                              &lt;/goals&gt;
                              &lt;configuration&gt;
                                  &lt;target&gt;
                                      &lt;delete
                                          file="${project.build.directory}/${project.build.finalName}/WEB-INF/project.properties" /&gt;
                                      &lt;copy file="src/main/config/prod/project.properties"
                                          tofile="${project.build.directory}/${project.build.finalName}/WEB-INF/project.properties" /&gt;
                                  &lt;/target&gt;
                              &lt;/configuration&gt;
                          &lt;/execution&gt;
                      &lt;/executions&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.3&lt;/version&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
              &lt;resources&gt;
                  &lt;resource&gt;
                      &lt;directory&gt;src/main/resources/prod&lt;/directory&gt;
                  &lt;/resource&gt;
              &lt;/resources&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  </code></pre>
  
  <p>The problem is by the time <code>maven-antrun-plugin</code> gets a chance to run, the <code>war</code> has already been packaged. The ant <code>&lt;target&gt;</code> does run and makes appropriate changes, but too late.</p>
  
  <p>The command line:</p>
  
  <pre><code>$ mvn -Pprod-build clean install
  </code></pre>
  
  <p>mvn output:</p>
  
  <pre><code>    [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] ------------------------------------------------------------------------
  </code></pre>
  
  <p>Any pointers will be greatly appreciated.</p>