Filtering using resources

Now, let us see how we can put the resources features of Maven to good use, that is, to perform variable replacements on project resources. This feature is useful when you need to parameterize a build with different configuration values, depending on the deployment platform.

You can define variables in your resources. Let us see how we can get the value of these variables from properties, resource filter files, and the command line.

How to do it...

To perform filtering using resources, use the following steps:

  1. Add a property with a variable in the src/main/resource/app.properties file:
    display.name=Hello ${project.name}
  2. Add the following code in the pom file:
     <build> <resources> <resource> <directory>src/main/resources</directory> ...

Get Apache Maven Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.