0

我有一个要求,我使用 -D 选项传递属性+值。我想访问 pom.xml 文件中的值。你能帮我知道我怎样才能达到同样的效果吗?

例如:-Dname="BlaBla"

现在在 pom.xml 文件中如何获取“名称”的值?感谢你的帮助。

4

1 回答 1

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
于 2013-06-24T08:02:18.567 回答