Where are the three places that I can specify profiles?
Author: Deron Eriksson
Description: This tutorial describes three ways to specify profiles in maven.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


Page:    1 2 >

In mavenSW, profiles can be specified in three places: settings.xml (global or user), pom.xml, or profiles.xml. The global settings.xml file is located in the conf directory within the maven installation. The user setting.xml file is located in the .m2 directory within the user home directory. The pom.xml file is located within a maven project (which can also be inherited by a child project, which also has a pom.xml file). A profiles.xml file can exist in a project at the root level (the same level as a pom.xml file).

Here is an example of a fragment of my user settings.xml file defines a 'settings.xml.profile' profile and activates it:

settings.xml

...
	<profiles>
		<profile>
			<id>settings.xml.profile</id>
			<properties>
				<settings.xml.property>settings xml property</settings.xml.property>
			</properties>
		</profile>
	</profiles>
...
	<activeProfiles>
		<activeProfile>settings.xml.profile</activeProfile>
	</activeProfiles>
...

Here is a project called 'aproject' that contains a standard pom.xml file plus a profiles.xml file.

'aproject' project

The pom.xml file defines a 'pom.xml.profile' profile and activates it via the 'activeByDefault' element.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.maventest</groupId>
	<artifactId>aproject</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>aproject</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<profiles>
		<profile>
			<id>pom.xml.profile</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<properties>
				<pom.xml.property>pom xml property</pom.xml.property>
			</properties>
		</profile>
	</profiles>
</project>

The profiles.xml file defines a 'profiles.xml.profile' profile. By default it will be active.

profiles.xml

<profiles>
	<profile>
		<id>profiles.xml.profile</id>
		<properties>
			<profiles.xml.property>profiles xml property</profiles.xml.property>
		</properties>
	</profile>
</profiles>

(Continued on page 2)

Page:    1 2 >