【问题标题】:What is Maven's counterpart of Ant's <property> "prefix" attribute?Ant 的 <property> “前缀”属性的 Maven 对应物是什么?
【发布时间】:2013-03-29 10:56:22
【问题描述】:

我目前正在将 Java Web 项目构建过程从 Ant 迁移到 Maven。当前进程使用几个特定于环境的属性文件,这些文件在 WAR 文件生成期间根据提供给 Ant 的环境参数插入到主要应用程序属性中。

我无法在 Maven 中轻松复制的功能之一是属性文件前缀,即:

<property name="some.env.file" value="someEnv.properties"/>
<property file="${some.env.file}" prefix="some.env"/>

这会将文件中的所有属性都以“some.env”作为前缀,并且应用程序属性中的所有占位符都包含此前缀,即:

some.property=${some.env.propertyOne}

Maven 提供了 pom.xml 过滤器和过滤元素以允许替换属性,但我无法找到一种方法来在文件中添加所有属性名称,并将特定于环境的前缀设置为构建参数,这迫使我重复属性文件用于 Maven 构建过程。有没有办法在 Maven 中复制这个 Ant 的原始功能?

【问题讨论】:

    标签: java maven web-applications ant


    【解决方案1】:

    我建议您使用 maven-antrun-plugin 使用前缀通过简单的 ant 任务加载属性文件。并且还启用exportAntProperties 以便由ant 定义的属性在maven 中可用。

    这样的事情会在验证阶段(以及所有后续阶段)在您的 maven 构建中提供 ant 定义的所有属性。

     <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <configuration>
              <exportAntProperties>true</exportAntProperties>
              <target>
                <property file="${some.env.file}" prefix="some.env"/>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-25
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2015-12-15
      相关资源
      最近更新 更多