Search code examples
xmlmavenprofilesmaven-war-plugin

Generating custom WAR archives with Maven profiles


I need to produce different WARs from a Maven project, according to values that vary between profiles.

For some files, I have default values that may be overwritten by configuration. For example, I might have an images folder with default images, and the "prof1" profile might overwrite some of them, while the "prof2" profile might use only the default images.

I'm having troubles implementing this using the Maven War Plugin. I listed the different webresources in the config shown below, but the values are not overridden - instead, the default images are always shown. It's probably relevant that I placed the web application files into the /Webcontent/ directory, instead of /src/main/webapp; I could switch back if needed.

Here's my maven war plugin configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <overwrite>true</overwrite>
        <webResources>  
            <resource>
                <directory>${basedir}/WebContent</directory>
                <excludes>
                    <exclude>**/resources/*</exclude>
                </excludes>
            </resource> 
            <resource>
                <directory>${basedir}/WebContent/resources</directory>
                <targetPath>WEB-INF/classes</targetPath>
                <filtering>true</filtering>
            </resource>
            <resource >
                <directory>${basedir}/version/${profile.name}</directory>
            </resource>
        </webResources>
        <archiveClasses>false</archiveClasses>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix />
            </manifest>
        </archive>
    </configuration>
</plugin>

Solution

  • I had the same problem, apparently resources in the WebContent portion of your app are not handled by this kind of filtering, I used the approach where you copy resources for a particular profile to a temporary build folder,and then combine it with the war, it's outlined here:

    http://edeustace.wordpress.com/2010/07/08/processing-resources-with-the-maven-war-plugin/

    and that worked great-