Java 通过包含另一个属性文件来扩展属性文件。专家
我可以使用“包含”选项(或类似的选项)将任何属性文件包含到另一个属性文件中吗 因此,我有两个属性文件: 1.“firstPropertiesFile”,其中包含下一个字符串: include=secondPropertiesFile#它是指向第二个属性文件的路径 及 “secondPropertiesFile”包含下一个字符串: 键=值 此外,我还有一个资源文件(将由resources:resources-goal筛选的文件)包含: ${key} 当我调用resources:resources目标时,我希望接下来的步骤是:Java 通过包含另一个属性文件来扩展属性文件。专家,java,maven,properties-file,Java,Maven,Properties File,我可以使用“包含”选项(或类似的选项)将任何属性文件包含到另一个属性文件中吗 因此,我有两个属性文件: 1.“firstPropertiesFile”,其中包含下一个字符串: include=secondPropertiesFile#它是指向第二个属性文件的路径 及 “secondPropertiesFile”包含下一个字符串: 键=值 此外,我还有一个资源文件(将由resources:resources-goal筛选的文件)包含: ${key} 当我调用resources:resources目
(“包括”章节)。标准Java属性中没有内置任何内容可以实现这一点,如果您想要实现这一点,您需要对其进行编码,或者使用已经实现了这一点的库。在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>
org.codehaus.mojo
属性maven插件
${properties maven plugin.version}
读取属性
产生资源
读取项目属性
firstPropertiesFile.properties
secondPropertiesFile.properties
写入所有属性
产生资源
写入项目属性
${project.build.directory}/allprops.properties