java - 如何将 .properties 文件从父项目共享到子项目
问题描述
我有一个带有 .properties 文件的父项目,该文件根据项目上定义的配置文件进行过滤,该项目有子项目或模块,我希望过滤的 .properties 文件可用于子项目,我可以使用java中的resourceBoundle或其他方式访问文件的属性。
我尝试使用,没有运气 如何在 Maven2 模块之间共享过滤器文件?-> MojoHaus 项目
家长会
<?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 父项目中,这个文件在 extras 中被过滤,当我通过它时,我希望它更新其他内部文件属性
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>
推荐阅读
- r - 拆分矩阵列,无需中间转换为矩阵
- python - 将 tkinter 条目链接到彼此的输入
- heroku - 是否可以在 Heroku 上运行不和谐音乐机器人?
- ansible - 使用 Ansible 安装 Elastic Search 插件
- javascript - SVG 动画在加载时触发,而不是在 DOM 插入时触发
- html5-video - 如何为 HTML 视频创建类似 youtube 的搜索栏预览图像
- reactjs - 方法屏幕有消息 - 未解决的功能或方法
- r - R中有没有办法让table1根据列的总和而不是通过计算行数来计算百分比?
- jetty - Jetty 将 9.3.27 升级到 9.4.43 - 构建成功但应用程序部署失败“共享调度程序未启动”错误
- javascript - 运行 npm run start 时出现错误“当前未启用对实验语法 'jsx' 的支持”