Enterprise Java Development@TOPIC@
Provide groups of conditional configuration
Adds flexibility to build
Flexibility can sometimes add confusion for both developers and build tools -- be careful
Can consist of
properties
dependencies
build elements
...
Cannot include GAV elements
<profile> <!-- defines our default database -->
<id>h2db</id>
<properties>
<jdbc.driver>org.h2.Driver</jdbc.driver>
<jdbc.url>jdbc:h2:\${basedir}/target/h2db/ejava</jdbc.url>
<jdbc.user>sa</jdbc.user>
<jdbc.password/>
<hibernate.dialect>
org.hibernate.dialect.H2Dialect
</hibernate.dialect>
</properties>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
The example above defines the properties and dependencies for the H2 database driver
when the h2db
profile is active
Use -P(profile)
to manually trigger a profile to be included
$ mvn test -Ph2db
Use -P!(profile)
to manually trigger a profile to be excluded. Use -P\!(profile) with bash shell
$ mvn test -P\!h2db
Specify an active profile in settings..xml
<activeProfiles> <activeProfile>jboss7</activeProfile> <activeProfile>h2db</activeProfile> </activeProfiles>
Property having a value
<profile>
<id>h2db</id>
<activation>
<property>
<name>jdbcdb</name>
<value>h2</value>
</property>
</activation>
The h2db profile will activate when -Djdbc=h2 is specified on the command line
Property existing
<profile>
<id>h2db</id>
<activation>
<property>
<name>h2db</name>
</property>
</activation>
The h2db profile will activate when -Dh2db is specified on the command line -- no matter the value
Property not existing
<profile>
<id>h2db</id>
<activation>
<property>
<name>!h2db</name>
</property>
</activation>
The h2db profile will activate when -Dh2db is not specified
Property not a spefici value
<profile>
<id>h2db</id>
<activation>
<property>
<name>jdbcdb</name>
<value>!hsql</value>
</property>
</activation>
The h2db profile will activate in cases when -Dhsql is not equal to hsql