Tuesday, April 28, 2009

Using properties in pom

the hibernate-annotations and hibernate-commons-annotations version since these should match. We’ll do this by creating a property called hibernate-annotations-version. The resulting simple-parent section looks like this:

<project>
...
<properties>
<hibernate.annotations.version>3.3.0.ga</hibernate.annotations.version>
</properties>

<dependencyManagement>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>${hibernate.annotations.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>${hibernate.annotations.version}</version>
</dependency>
...
</dependencyManagement>
...
</project>


If you put this XML in a pom.xml and run mvn help:effective-pom, you will see that the output contains the line:



<version>3.3.0.ga</version>

Maven provides three implicit variables which can be used to access environment variables, POM information, and Maven Settings:
env
The env variable exposes environment variables exposed by your operating system or shell. For example, a reference to ${env.PATH} in a Maven POM would be replaced by the ${PATH} environment variable (or %PATH% in Windows).
project
The project variable exposes the POM. You can use a dot-notated (.) path to reference the value of a POM element. For example, in this section we used the groupId and artifactId to set the finalName element in the build configuration. The syntax for this property reference was: ${project.groupId}-${project.artifactId}.
settings
The settings variable exposes Maven settings information. You can use a dot-notated (.) path to reference the value of an element in a settings.xml file. For example, ${settings.offline} would reference the value of the offline element in ~/.m2/settings.xml.


In addition to the three implicit variables, you can reference system properties and any custom properties set in the Maven POM or in a build profile:


Java System Properties
All properties accessible via getProperties() on java.lang.System are exposed as POM properties. Some examples of system properties are: ${user.name}, ${user.home}, ${java.home}, and ${os.name}. A full list of system properties can be found in the Javadoc for the java.lang.System class.


Arbitrary properties can be set with a properties element in a pom.xml or settings.xml, or properties can be loaded from external files.

No comments:

Post a Comment