【发布时间】:2015-07-15 13:13:32
【问题描述】:
我知道在很多情况下,可以使用两个配置文件(虽然笨拙但)导致从文件中读取属性(如果存在)并设置默认值,例如
<profile>
<id>my-default-props</id>
<activation>
<file>
<missing>${my.file.path}</missing>
</file>
</activation>
<properties>
<my.prop1>Blah</my.prop1>
<my.prop2>Another</my.prop2>
</properties>
</profile>
<profile>
<id>read-my-props</id>
<activation>
<file>
<exists>${my.file.path}</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${my.file.path}</file>
</files>
<quiet>false</quiet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
不幸的是,这对我不起作用:我需要在各种子项目中覆盖“my.file.path”的值,但配置文件激活是在生命周期的早期评估的。这意味着在评估期间不使用子项目的值,并且永远不会正确读取属性。
这对我来说似乎是一个足够普遍的要求,但谷歌搜索却告诉我不然。谁能告诉我如何实现这个目标?谢谢。
【问题讨论】:
-
您能否详细说明这些配置文件的目的是什么?你想通过这个实现什么?
-
主要是为了让构建与本地应用实例共享属性。例如,应用程序可能配置为使用名为
my_app_db的数据库,而我希望构建(例如用于集成测试)采用相同的数据库配置。
标签: maven properties-file