从Maven中的POM文件读取属性文件

时间:2013-02-06 09:06:41

标签: maven pom.xml

为什么这不起作用?如何从属性文件中选择版本号。

在pom.xml中读取属性

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
          </execution>
          <configuration>
            <files>
              <file>dev.properties</file>
            </files>
          </configuration>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

在dev.properties

org.aspectj.aspectjrt.version = 1.6.11

pom.xml中的依赖

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj.aspectjrt.version}</version>
        </dependency>

错误:依赖项必须是有效版本

1 个答案:

答案 0 :(得分:-1)

此构建作业的properties(dev.properties)文件。

<files>
   <file>dev.properties</file>
</files>

对于依赖项,您需要在pom.xml文件中添加如下所示。

<properties>

<org.aspectj.aspectjrt.version>1.6.11</org.aspectj.aspectjrt.version>
</properties>
相关问题