Search code examples
javamavenmaven-3maven-pluginmaven-module

Using Configuration files in multi-module maven project


I am working on multi-module maven project (newbe to multi-module maven projects).

I have Module A with the directory structure /ModuleA/ConfigFiles/config.properties.

And Module B which uses the Module A using maven dependency.

Now Module A source file retrieves the config file as

String configFile = System.getProperty("user.dir")+"\\ConfigFiles\\config.properties";

So when I call the Module A function from Module B , it is using Module B local project directory instead of Module A's project directory.

Is there any solution/workaround to this in multi-module project ?


Solution

  • I think that using resources mechanics here is the best approach. Just place your config file somewhere in src/main/resources directory of Module A. Next change your code that read config file respectively (here is some information how to read from resource files).

    After that change you will read config from classpath, not from exact directory and there will be no difference whether you call your function from Module A or Module B.