【问题标题】:Extend properties file by including another properties file. Maven通过包含另一个属性文件来扩展属性文件。马文
【发布时间】:2015-03-13 06:53:19
【问题描述】:

我可以使用“包含”选项(或类似的选项)将任何属性文件包含到另一个属性文件中吗?

所以,我有两个属性文件: 1. "firstPropertiesFile" 包含下一个字符串:

include = secondPropertiesFile #第二个属性文件的路径

"secondPropertiesFile" 包含下一个字符串:

键=值

我还有资源文件(将被资源过滤的文件:资源目标)包含:

${key}

当我调用 resources:resources 目标时,我期待接下来的步骤:

  1. 资源插件查看 firstPropertiesFile 文件并查看它包含对另一个属性文件的引用。

  2. 插件转到引用(第二个属性文件的路径)并查看必要的键并获取值(在我们的例子中为值)。

但是这种方式在 maven 中不起作用。你能提示我如何实现这一点吗?

附: Apache Commons 配置支持此选项:http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html (“包括”一章)。

【问题讨论】:

    标签: java maven properties-file


    【解决方案1】:

    标准 Java 属性没有内置任何内容来执行此操作,如果您需要,您需要对其进行编码或使用已经执行此操作的库。

    【讨论】:

      【解决方案2】:

      在 Maven 中,您可以实现非常相似的Properties Maven Plugin

      我不支持您期望的 include 语义,但它可以从多个来源组成一个属性文件。下面的示例将结合两个属性文件,您可以从 allprops.properties 访问它们。当必须在不同的系统或环境中使用不同的属性文件集时,这尤其有用。

      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>${properties-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>read-properties</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>read-project-properties</goal>
                </goals>
                <configuration>
                  <files>
                    <file>firstPropertiesFile.properties</file>
                    <file>secondPropertiesFile.properties</file>
                  </files>
                </configuration>
              </execution>
              <execution>
                <id>write-all-properties</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>write-project-properties</goal>
                </goals>
                <configuration>
                  <outputFile>${project.build.directory}/allprops.properties</outputFile>
                </configuration>
              </execution>            
            </executions>
          </plugin>
        </plugins>
      

      【讨论】:

        猜你喜欢
        • 2016-08-24
        • 2014-06-09
        • 2016-01-20
        • 2017-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多