0

I'm trying to leverage the useful overlay feature of the maven-war-plugin. In other words, I have a template (packaged as WAR file, template-0.0.1.war) containing tag files, css, js and images.

When I set template-0.0.1.war as a dependency of the myApp project I get a final myApp.war containing all the files of template-0.0.1.war overwritten by those with the same path in the myApp project.

This is the behavior I want.

However, I need to introduce in the pom.xml of myApp a configuration of the maven-war-plugin:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
      <webResources>
        <resource>
          <directory>../path/to/another/dir</directory>
        </resource>
      </webResources>
    </configuration>
</plugin>

As soon as I introduce such a configuration of the plugin, I obtain the final myApp.war with all the files from both template-0.0.1.war and myApp project but the files of template-0.0.1.war overwrite those with the same path in the myApp project.

This behavior is exactly the opposite of what I expect.

Can someone tell me where I'm wrong?

Thanks in advance.

Edit after the solution was found:

The described issue is due to the concurrency of different actions: the WAR overlay (which works correctly) and the external webResources.

In fact, the external webResources tag points to the template project directory: totally unuseful for Maven, but indispensable to "fool" the m2e eclipse plugin and let it see the custom tags contained in the template.

The solution I have adopted is to introduce 2 different profiles in the plugin section of my pom.xml: the first one called "eclipse" in which I inserted the maven-war-plugin with the webResources and a second profile (called "standard" and activated by default) without the maven-war-plugin.

baronKarza
  • 513
  • 6
  • 23

1 Answers1

0

From the maven war plugin documentation:

By default, the source of the project (a.k.a the current build) is added first (e.g. before any overlay is applied). The current build is defined as a special overlay with no groupId, artifactId. If overlays need to be applied first, simply configure the current build after those overlays.

If you have files in the template that are being overwritten by files in the child WAR, you may want to consider explicitly excluding them in the overlay configuration.

Here's what the documentation says to apply the overlay first:

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
      <overlays>
        <overlay>
          <groupId>com.example.projects</groupId>
          <artifactId>my-webapp</artifactId>
        </overlay>
        <overlay>
          <!-- empty groupId/artifactId represents the current build -->
        </overlay>
      </overlays>
    </configuration>
  </plugin>
</plugins>

TheAmpersand
  • 200
  • 1
  • 11
  • Many thanks for your quick answer but it does not solve the problem (see the edit in my post). Only last night I realized that the issue was due to different actions overriding each other.It's my guilt that I didn't provide complete information. Sorry. – baronKarza Feb 15 '13 at 07:53