0

I am having a requirement where I am passing a property+value with -D option. I would like to access the value in pom.xml file. Could you please help me to know how can I achieve the same?

For example: -Dname="BlaBla"

now in pom.xml file how I can get the value of "name"? Thanks for all your help.

Sudipta Deb
  • 1,040
  • 3
  • 23
  • 43

1 Answers1

0

The handling of properties in maven is described here: POM Reference -> Properties

In your case just use: ${name}

Example:

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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>property-test</groupId>
  <artifactId>property-test</artifactId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <echo>Value of FooBar is: ${FooBar}</echo>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

Call:

mvn validate -DFooBar="Hello World"

Result:

 [echo] Value of FooBar is: Hello World
FrVaBe
  • 47,963
  • 16
  • 124
  • 157