0

我有一个项目 TestA,它依赖于另一个项目 TestB,并且在 pom.xml 中提到了这一点。现在,我需要在运行时从 TestA 加载 TestB 中存在的一些配置文件。知道怎么做吗?

4

2 回答 2

0

maven-remote-resources-plugin 将为您提供帮助。基本上你:

  1. 创建一个仅包含配置文件的子模块。
  2. 使用子模块 POM 中的插件将配置文件打包并安装到本地存储库中。
  3. 在依赖这些配置的其他子模块的 POM 中引用已安装的配置文件包。

有关详细信息,请参阅http://maven.apache.org/plugins/maven-remote-resources-plugin/

于 2013-06-19T18:11:12.620 回答
0

例如,如果您有配置文件 configuration.properties

将配置文件放在TestB/src/main/resources/configuration.properties

在要恢复 configuration.properties 的 TestA 中,

如果您正在执行非静态方法,

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("configuration.properties");

如果您正在执行静态方法,

InputStream inputStream = ClassContainsStaticMethod.class.getClassLoader().getResourceAsStream("configuration.properties");
于 2013-06-19T18:13:29.847 回答