1

In one of module 'scheduler' classes I need to use data from properties file from modules : backend, common end entity-managers (e.g). Properties file are held in (module)/src/main/resources. How to achieve that?

Piotr Sołtysiak
  • 998
  • 5
  • 13

2 Answers2

0

Below are the two options I can think of:

1) In eclipse, for scheduler module, add other modules (e.g. backend) as dependencies (R-click on project > Build Path > Configure Build Path > Projects > Add). This will add the classpath entries of the added projects in scheduler classpath. If you are using maven, you may have to add the projects as internal dependencies in pom.xml of scheduler module as well.

2) Externalize the properties file by putting it outside your project structure, somewhere on the filesystem - e.g. under C:\properties directory. Add this directory to your project classpaths for modules, which use the property file. You can do this in eclipse by (R-click on project > Build Path > Configure Build Path > Libraries > Add Variable). Also ensure that the directory is there on your classpath when you run your application. If you are running it as standalone java application, then add the path in -cp switch of java command. If you are running it in any container, add the directory to your container's classpath.

Pat
  • 2,223
  • 4
  • 19
  • 25
  • 1) Done 2) I dont think it's good solution. Resources files should stay where they are now, they are used in some other places inside modules – Piotr Sołtysiak Jul 30 '14 at 08:12
  • Did option 1 work for you? Also, I always prefer to externalize the property files, if they contain business data or if they differ across environments (dev, test, prod) - this allows me to use the same binary across all envs and manage the environment specific values through external prop file. Otherwise, you would need to build your binary specific to each env, which may be dangerous if you have not configured your build properly. – Pat Jul 30 '14 at 08:25
0

You can access them easily using the ClassLoader.

this.getClass().getClassLoader().getResourceAsStream("myproperties.properties");    

This will return the stream to the file, even if the file is in a different jar file.

Remind: Modules should stay seperated, try changing your code to go without such dependencies. Is it possible to set the necessery values on schedular initialization instead of reading them in scheduler itself?

Robert
  • 230
  • 2
  • 9