Question

I need to create two WAR files with two different web.xml files using Maven. The WAR files are the same otherwise.

The WAR files are created as expected, however, the second file has the same web.xml file as the first.

How can I force the Maven WAR plugin to use the second file for the second WAR? I cannot use profiles since I need both files created in one pass.

My current code:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <warSourceDirectory>${basedir}/WEB</warSourceDirectory>
    <warName>main</warName>
    <webXml>${basedir}/CONF/web.xml</webXml>
  </configuration>
  <executions>
    <execution>
      <id>hist-war</id>
      <phase>package</phase>
      <goals>
        <goal>war</goal>
      </goals>
      <configuration>
        <warName>hist</warName>
        <warSourceDirectory>${basedir}/WEB</warSourceDirectory>
        <webXml>${basedir}/CONF/hist.web.xml</webXml>
      </configuration>
    </execution>
  </executions>
</plugin>
Was it helpful?

Solution

Use the overlay feature of the Maven WAR plugin.

You need two WAR projects. The first is your original one, with its web.xml file in the correct place. This doesn't have any specific needs in terms of configuration. Just ensure that it builds as you expect.

The second only contains its POM and the alternate web.xml in the WEB-INF directory. This project's POM must contain a dependency on the first project with type specified as war and scope specified as runtime. You should not need to explicitly configure the Maven WAR plugin.

OTHER TIPS

seems there are a variety of gotchas using the war plugin. in this case, i would just use 2 separate sub-modules to build the appropriate wars.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top