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

Profile Activation

In the previous section, we showed you how to create a profile that overrides default behavior for a specific target environment. In the previous build, the default build was designed for development, and the production profile exists to provide configuration for a production environment. What happens when you need to provide customizations based on variables such as operating systems or JDK version? Maven provides a way to “activate” a profile for different environmental parameters. This is called profile activation.

Take the following example. Assume we have a Java library that has a specific feature available only in the Java 6 release—the Scripting Engine as defined in JSR-223 (see http://jcp.org/en/jsr/detail?id=223). You’ve separated the portion of the library that deals with the scripting library into a separate Maven project, and you want people running Java 5 to be able to build the project without attempting to build the Java 6 specific library extension. You can do this by using a Maven profile that adds the script extension module to the build only when the build is running within a Java 6 JDK. First, let’s take a look at our project’s directory layout and how we want developers to build the system.

When someone runs mvn install with a Java 6 JDK, you want the build to include the simple-script project’s build; when they are running in Java 5, you would like to skip the simple-script project build. If you failed to skip the simple-script project build ...

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