我目前正在将 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 的原始功能?
最佳答案
我建议您使用 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>
关于java - Ant 的 <property> "prefix"属性的 Maven 对应项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15701865/