Using properties (variables) in xml files such as pom.xml

The following pom.xml is from the mvc-basic » example.

As you can see, at the top, under the <properties> node there are a couple tags, one of which is <org.slf4j.version>1.5.10</org.slf4j.version>. The tag itself becomes the property or variable name and can be referenced later in the xml as ${org.slf4j.version} as in <version>${org.slf4j.version}</version>.

<?xml version="1.0" encoding="UTF-8"?>
<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>org.springframework.samples</groupId>
        <artifactId>org.springframework.samples.mvc.basic</artifactId>
        <name>mvc-basic</name>
        <packaging>war</packaging>
        <version>1.0.0-SNAPSHOT</version>
        <properties>
                <org.springframework.version>3.0.0.RELEASE</org.springframework.version>
                <org.slf4j.version>1.5.10</org.slf4j.version>
        </properties>
        <dependencies>

                <!--  Spring -->
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-context</artifactId>
                        <version>${org.springframework.version}</version>
                        <exclusions>
                                <!-- Exclude Commons Logging in favor of SLF4j -->
                                <exclusion>
                                        <groupId>commons-logging</groupId>
                                        <artifactId>commons-logging</artifactId>
                                 </exclusion>
                        </exclusions>
                </dependency>
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-webmvc</artifactId>
                        <version>${org.springframework.version}</version>
                </dependency>

                <!-- Logging -->
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>${org.slf4j.version}</version>
                </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>jcl-over-slf4j</artifactId>
                        <version>${org.slf4j.version}</version>
                        <scope>runtime</scope>
                </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                        <version>${org.slf4j.version}</version>
                        <scope>runtime</scope>
                </dependency>
                <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>1.2.15</version>
                        <exclusions>
                                <exclusion>
                                        <groupId>javax.mail</groupId>
                                        <artifactId>mail</artifactId>
                                </exclusion>
                                <exclusion>
                                        <groupId>javax.jms</groupId>
                                        <artifactId>jms</artifactId>
                                </exclusion>
                                <exclusion>
                                        <groupId>com.sun.jdmk</groupId>
                                        <artifactId>jmxtools</artifactId>
                                </exclusion>
                                <exclusion>
                                        <groupId>com.sun.jmx</groupId>
                                        <artifactId>jmxri</artifactId>
                                </exclusion>
                        </exclusions>
                        <scope>runtime</scope>
                </dependency>

                <!--  JSR 303 with Hibernate Validator -->
                <dependency>
                        <groupId>javax.validation</groupId>
                        <artifactId>validation-api</artifactId>
                        <version>1.0.0.GA</version>
                </dependency>
                <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-validator</artifactId>
                        <version>4.0.2.GA</version>
                </dependency>

                <!--  Joda Time -->
                <dependency>
                        <groupId>joda-time</groupId>
                        <artifactId>joda-time</artifactId>
                        <version>1.6</version>
                        <scope>runtime</scope>
                </dependency>

                <!--  URL Rewrite -->
                <dependency>
                        <groupId>org.tuckey</groupId>
                        <artifactId>urlrewritefilter</artifactId>
                        <version>3.1.0</version>
                </dependency>

                <!-- Servlet -->
                <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>servlet-api</artifactId>
                        <version>2.5</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>javax.servlet.jsp</groupId>
                        <artifactId>jsp-api</artifactId>
                        <version>2.1</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>jstl</artifactId>
                        <version>1.2</version>
                </dependency>

                <!-- Test -->
                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.7</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>
        <repositories>
                <!-- For JSR 303 and Hibernate Validator only - Encourage JBoss to publish these artifacts to Maven Central! -->
                <repository>
                        <id>org.jboss.repository.maven</id>
                        <url>http://repository.jboss.org/maven2</url>
                        <snapshots><enabled>false</enabled></snapshots>
                </repository>
        </repositories>
        <build>
                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <configuration>
                                        <source>1.5</source>
                                        <target>1.5</target>
                                        <showWarnings>true</showWarnings>
                                </configuration>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-war-plugin</artifactId>
                                <configuration>
                                        <warName>mvc-basic</warName>
                                </configuration>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-dependency-plugin</artifactId>
                                <executions>
                                        <execution>
                                                <id>install</id>
                                                <phase>install</phase>
                                                <goals>
                                                        <goal>sources</goal>
                                                </goals>
                                        </execution>
                                </executions>
                        </plugin>
                </plugins>
        </build>
</project>

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.