If you want to filter and copy your project resources to the output directory, the Apache Maven Resources Plugin is the best plugin to perform that. But sometimes you want to filter and rename resources with Maven and the last version of the Maven Resources Plugin (current 3.0.1) does not provide a direct way to do that.

This tutorial will show a workaround to filter and rename resources with Maven.

Project example

Let’s consider a file file-to-rename.txt located under src/main/ which  we want to filter and rename to renamed-file.txt.

Below the project structure :

Maven project structure

Maven project structure

The content of file-to-rename.txt :

Content of pom.xml :

Building the project

Run a mvn install to build the project if you use command line or Right-Click -> Run As -> Maven install on Eclipse.

After a refresh, below the new project structure :

Maven project output directory

Maven project output directory

And the content of renamed-file.txtis :

What happened ?

The project build is on two step. First maven-resources-plugin is used at the copy-resources lifecycle phase to filter the  resources located under /src/main and copy them to the target directory. Next, copy-rename-maven-plugin is used to rename the filtered output file file-to-rename.txt to renamed-file.txt.