0

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 ?

Carl
  • 83
  • 1
  • 5
  • 1
    Why are you referencing the config file based on your src directory? What happens to it when you package your project? – Oleg Nov 29 '17 at 11:45
  • I am not sure, since I am new to this one. I created one maven module and it needs config file of its own, which is used only by that module. So I used its base directory to store the config file. And the other module which is inheriting it (as Maven dependency) is calling those functions. Since I am calling **"user.dir"** , jvm is accessing the inherited module base folder instead of base module directory. – Carl Nov 29 '17 at 15:11

1 Answers1

2

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.

CDV
  • 106
  • 3