Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: Use the filtering mechanism for text files not under 'resources'?

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.

like image 564
wishihadabettername Avatar asked Oct 13 '22 22:10

wishihadabettername


1 Answers

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>
like image 177
Pascal Thivent Avatar answered Nov 02 '22 12:11

Pascal Thivent