tags:

views:

1037

answers:

2

I'm trying to get Maven to perform several executions with the WAR plugin. It works fine as long as it's defined in the following way:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
<version>1.0</version>
    <configuration>
    (...)
    </configuration>

But not in the following manner

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
            (...)
            </configuration>
        </execution>
    </executions>
</plugin>

Where Maven can't find any of the resources I defined in the <configuration> tag. Have I missed anything important, and/or is there a better way of constructing multiple WAR files in a single build?

A: 

The second version applies the configuration only to the phase you've specified. I'm not able to confirm this right now, but I'd guess it is not being applied because you haven't specified a goal for the configuration to be applied to.

If you add the war goal definition into the execution does it get applied? Like so:

<executions>
    <execution>
        <phase>package</phase>
        <goals>
          <goal>war</goal>
        </goals>
        <configuration>
        (...)
        </configuration>
    </execution>
</executions>
Rich Seller
Nice idea, but no deal :/ Thanks though.
mikek
+1  A: 

I didn't see how to turn off the war that's generated by default, but you can use one configuration outside the <executions> element and the rest inside:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-beta-1</version>
    <configuration>
      <classifier>with-junk</classifier>
      <!-- temp directory that the webapp is assembled in (each must be different) -->
      <webappDirectory>${project.build.directory}/build-with-junk</webappDirectory>
      <webResources>
        <resource>
          <directory>junk</directory>
          <includes>
            <include>**/*</include>
          </includes>
        </resource>
      </webResources>
    </configuration>
    <executions>
      <execution>
        <id>add-other-junk</id>
        <phase>package</phase>
        <goals>
          <goal>war</goal>
        </goals>
        <!-- exclude prior configuration -->
        <inherited>false</inherited>
        <configuration>
          <classifier>with-other-junk</classifier>
          <webappDirectory>${project.build.directory}/build-other-junk</webappDirectory>
          <webResources>
            <resource>
              <directory>other-junk</directory>
              <includes>
                <include>**/*</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </execution>
    </executions>
  </plugin>

For me, this builds artifact-0.1-with-junk.war and artifact-0.1-with-other-junk.war and both have the correct files included.

Justin W