0

I have a project, TestA, that depends on another project, TestB and this is mentioned in the pom.xml. Now, I need to load a few configuration files that are present in TestB from TestA at runtime. Any idea how to do it?

Kathy
  • 96
  • 2
  • 9

2 Answers2

0

The maven-remote-resources-plugin will help you. Basically you:

  1. Create a sub-module with just configuration files.
  2. Use the plugin in the sub-module POM to package and install the configuration files into your local repo.
  3. Reference the installed configuration file package in the POM of other sub-modules that depend on those configurations.

See http://maven.apache.org/plugins/maven-remote-resources-plugin/ for details.

lreeder
  • 12,047
  • 2
  • 56
  • 65
0

For example if you have the configuration file configuration.properties

Put the configuration file in TestB/src/main/resources/configuration.properties

In TestA where you want to recover the configuration.properties,

If you are executing non-static method,

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

If you are executing static method,

InputStream inputStream = ClassContainsStaticMethod.class.getClassLoader().getResourceAsStream("configuration.properties");