- There are text or XML property files which are used at deployment to set start-up or run-time properties.
- Use Maven build profiles to affect to values of these properties.
- Spring context values can then use these property names as variables, as post-compilation means to define bean properties.
In the pom.xml, is the profile section declaring the
<profiles> <profile> <id>dev</id> <properties> <durian.maxUsers>5</durian.maxUsers> </properties> </profile> </profiles>when a profile is specified in a maven build, the base declaration of the property is over-ridden with the one from the profile.
<properties> <durian.maxUsers>8</durian.maxUsers> </properties>Compare this result by looking back at the previous page on variable substitution. In the file
/durian/appbase/properties/a.propertiesthe variable ${durian.maxUsers}
maxUsers = ${durian.maxUsers}will result in
maxUsers = 5in the file
/durian/target/durian/WEB-INF/classes/properties/a.propertiesdue to the over-ride.
In Maven 3.0, profiles can be specified in three places.
- Per Project
Defined in the POM itself (pom.xml), as exemplified above. - Per User
Defined in the Maven-settings(%USER_HOME%/.m2/settings.xml - Shared
Defined in the global Maven-settings (%M2_HOME%/conf/settings.xml)
As documented in
http://books.sonatype.com/mvnref-book/reference/profiles-sect-maven-profiles.htmlthe following are elements that can be included in a pom build profile. Id is mandatory, needless to say.
<project> ..... <profiles> ..... <profile> <id>...</id> <build> <defaultGoal>...</defaultGoal> <finalName>...</finalName> <resources>...</resources> <testResources>...</testResources> <plugins>...</plugins> </build> <reporting>...</reporting> <modules>...</modules> <dependencies>...</dependencies> <dependencyManagement>...</dependencyManagement> <distributionManagement>...</distributionManagement> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <properties>...</properties> </profile> ..... </profiles> ..... </project>
When a profile is defined in a settings rather than a pom file, the following are elements that can be included in a pom build profile. Id is mandatory.
<settings> ..... <profiles> <profile> <id>...</id> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <properties>...</properties> </profile> </profiles> ...... </settings>
No comments:
Post a Comment