Skip to Main Content
Maven: The Definitive Guide
book

Maven: The Definitive Guide

by Sonatype Company
September 2008
Intermediate to advanced content levelIntermediate to advanced
470 pages
14h 22m
English
O'Reilly Media, Inc.
Content preview from Maven: The Definitive Guide

Resource Filtering

You can use Maven to perform variable replacement on project resources. When resource filtering is activated, Maven will scan resources for references to Maven property references surrounded by ${ and }. When it finds these references, it will replace them with the appropriate value in much the same way that the properties defined in the previous section can be referenced from a POM. This feature is especially helpful when you need to parameterize a build with different configuration values depending on the target deployment platform.

Often a .properties file or an XML document in src/main/resources will contain a reference to an external resource, such as a database or a network location that needs to be configured differently depending on the target deployment environment. For example, a system that reads data from a database has an XML document that contains the JDBC URL along with credentials for the database. If you need to use a different database in development and a different database in production, you can use a technology such as Java Naming and Directory Interface (JNDI) to externalize the configuration from the application in an application server, or you can create a build that knows how to replace variables with different values depending on the target platform.

Using Maven resource filtering, you can reference Maven properties and then use Maven profiles to define different configuration values for different target deployment environments. To illustrate ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Apache Maven Cookbook

Apache Maven Cookbook

Raghuram Bharathan
Mastering Apache Maven 3

Mastering Apache Maven 3

Prabath Siriwardena
Learning Apache Maven

Learning Apache Maven

Kevin Bowersox

Publisher Resources

ISBN: 9780596517335Supplemental ContentErrata Page