Book Image

Apache Maven Cookbook

Book Image

Apache Maven Cookbook

Overview of this book

Table of Contents (18 chapters)
Apache Maven Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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>
            <filtering>true</filtering>
          </resource>
        </resources>
      </build>
  3. Invoke the process-resources phase:

    mvn process-resources
    
  4. Examine the processed resource...