如何将 .properties 文件从父项目共享到子项目



我有一个带有 .properties 文件的父项目,该文件根据项目上定义的配置文件进行过滤,此项目有子项目或模块,我希望过滤的 .properties 文件可用于子项目,我可以使用 java 中的 resourceBoundle 或其他方式访问文件的属性。

我试图使用,没有运气 如何在 Maven2 模块之间共享过滤器文件?-> 魔术之家项目

父绒球

<?xml version="1.0" encoding="UTF-8"?>
<project 
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.data</groupId>
<artifactId>data2</artifactId>
<version>data-SNAPSHOT</version>
<packaging>pom</packaging>
<name>dataNameapp</name>
<modules>
<module>child  1</module>
<module>child  2</module>
</modules>
.....
</project>

子项目

reference parent properties in pom some code In guess

使用超过 Java 代码
child1/test.java

ResourceBundle resourceBundleProperties= ResourceBundle.getBundle("parentproperties")

更新

在mi父项目中,这个额外的文件被过滤,当我传递它时,我希望它更新其他内部文件属性

parent--extras/filtered.properties (file filtered)
child
--filters/filtered.properties (get from parent)  
--resources/final.properties  (filtered of filtered.properties)

您可以尝试使用Maven的资源插件从父项目复制文件,例如:

<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resourcesphase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/resources</outputDirectory>
<resources>          
<resource>
<directory>${project.parent.basedir}/src/resources/extras</directory>
<filtering>true</filtering>
</resource>
</resources>              
</configuration>            
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>

最新更新