views:

17

answers:

1

I need to customize a number of XML files which are not under resources (in particular, they are under an EAR's project src/main/application).

The filtering mechanism would be perfect for this, but my understanding (correct?) is that it works for resources only.

Is there a way to use filtering for files in other directories than src/main/resources?

Thanks in advance.

+1  A: 

The Maven EAR Plugin can filter the content of src/main/application. As documented in Filtering EAR Resources:

Filtering the sources

Filtering the content of the src/main/application directory or the one defined by the earSourcesDirectory parameter is as easy as:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.4.2</version>
        <configuration>
           <filtering>true</filtering>
           [...]
        </configuration>
      </plugin>
    </plugins>
  </build>

Note that the standard properties are available for filtering. It is also possible to specify a set of property files to add extra values if necessary. The configuration below uses also the properties defined in src/main/filters/config.properties

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.4.2</version>
        <configuration>
           <filtering>true</filtering>
           <filters>
             <filter>src/main/filters/config.properties</filter>
           </filters>
           [...]
        </configuration>
      </plugin>
    </plugins>
  </build>
Pascal Thivent
Thanks Pascal, this works great. I had an older version of the plugin which didn't have filtering.
wishihadabettername
@wishihadabettername You're welcome, glad it helped.
Pascal Thivent