Filter and rename resources with Maven

Source: http://roufid.com/filter-and-rename-resources-with-maven/ 17 DEC, 2016

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 renameresources 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 filetorename.txt located under src/main/ which  we want to filter and rename to renamedfile.txt.

Below the project structure :

Maven project structure

Maven project structure

The content of filetorename.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 renamedfile.txtis :

What happened ?

The project build is on two step. First maven-resources-plugin is used at the copyresources 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 filetorename.txt to renamedfile.txt.

References

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

粤ICP备15062915号-1