O'Reilly logo

Apache Maven Cookbook by Raghuram Bharathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required