java—通过包含另一个属性文件来扩展属性文件Maven

anhgbhbe  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(354)

我可以使用“include”选项(或类似的选项)将任何属性文件包含到另一个属性文件中吗?
所以,我有两个属性文件:1。“firstpropertiesfile”,其中包含下一个字符串:
include=secondpropertiesfile#它是第二个属性文件的路径

“secondpropertiesfile”,其中包含下一个字符串:
键=值
我也有资源文件(文件将被过滤)resources:resources goal)包含:
${key}
当我调用resources:resources goal,我期待下一步:
资源插件查看firstpropertiesfile文件并查看它是否包含引用另一个属性文件的内容。
该插件转到reference(第二个属性文件的路径)并查看必需的key和get value(在我们的例子中是-value)。
但这种方法在maven中不起作用。你能告诉我怎么实现这一点吗?
p、 在apache commons配置中支持此选项:http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html (“包括”章节)。

uxh89sit

uxh89sit1#

标准java属性中没有任何内置的东西可以做到这一点,如果您需要这样做,您需要对其进行编码,或者使用已经这样做的库。

vngu2lb8

vngu2lb82#

在maven中,可以实现与maven插件非常相似的属性。
我不支持您期望的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>

相关问题