Inherit common properties file

25 views
Skip to first unread message

etlam nahkcip

unread,
Mar 19, 2015, 4:08:12 AM3/19/15
to owne...@googlegroups.com
Hi there,

I have a Multi module project, in which I am using owner. At first thanks a lot for this nice Framework, I am using it for 2 days now and I am really convinced.

The project is structured as followed:

Parent
        |
        |
        |
        |----Module1
        |        |
        |        |
        |        |---properties1
        |----Module2
        |        |
        |        |
        |        |---properties2

In both proerties files, I am using the variable expansion to declare in which environment the App is running. For example: server.${environment}.database, where environment will be the same in both configurations.
Is it possible to declare a common properties File in the Parent module and let the sub modules inherit this file? As far as I've seen, it's possible to declare another proeprties file and the the Policy to Merge. BUT only with a static reference like "file:PATH_TO_FILE" isn't there something like "$workspace"?

Best Regards

Luigi R. Viggiano

unread,
Mar 19, 2015, 7:37:19 AM3/19/15
to owne...@googlegroups.com
Hi.

You are correct. You can use the merge policy specifying multiple sources for the configuration.

In the @Sources() annotation you can specify System Properties and Environment Variables. ${workspace} is something known by the IDE; if the IDE sets this as system variable, you can use it. On Unix systems (Linux/Mac) you have an environment variable called ${PWD} but I don't know if something similar is available on Windows. The $PWD variable should point to the working directory, that generally is set to the project dir by the IDE when running your application; so you could try with @Sources({file:"${PWD}/foobar.properties"}) or better just @Sources{"file:foobar.properties}, since if you don't specify the path, the URI file:foobar.properties will be resolved in the current working directory.

I think, the best option is to bind the workspace directory to a System property programmatically before calling ConfigFactory.create(), in a portable way. Eclipse or other IDE can probably be configured to run your app adding a system property binded with the IDE workspace, something like "-Dmyapp.config.base=${workspace}" in the run configurations. Then in your Config object you'll be able to specify @Sources({"file:${myapp.config.base}/foobar.properties"})

Hope this helps.

L.



--Luigi

Mobile: +39 366 521 5000
Skype: luigi.viggiano

--
You received this message because you are subscribed to the Google Groups "owner-api" group.
To unsubscribe from this group and stop receiving emails from it, send an email to owner-api+...@googlegroups.com.
To post to this group, send email to owne...@googlegroups.com.
Visit this group at http://groups.google.com/group/owner-api.
For more options, visit https://groups.google.com/d/optout.

etlam nahkcip

unread,
Mar 19, 2015, 8:19:50 AM3/19/15
to owne...@googlegroups.com, luigi.v...@newinstance.it
Hi,

and thanks for your answer!


Am Donnerstag, 19. März 2015 12:37:19 UTC+1 schrieb Luigi R. Viggiano:
Hi.

You are correct. You can use the merge policy specifying multiple sources for the configuration.

In the @Sources() annotation you can specify System Properties and Environment Variables. ${workspace} is something known by the IDE; if the IDE sets this as system variable, you can use it. On Unix systems (Linux/Mac) you have an environment variable called ${PWD} but I don't know if something similar is available on Windows. The $PWD variable should point to the working directory, that generally is set to the project dir by the IDE when running your application; so you could try with @Sources({file:"${PWD}/foobar.properties"}) or better just @Sources{"file:foobar.properties}, since if you don't specify the path, the URI file:foobar.properties will be resolved in the current working directory.

I think, the best option is to bind the workspace directory to a System property programmatically before calling ConfigFactory.create(), in a portable way. Eclipse or other IDE can probably be configured to run your app adding a system property binded with the IDE workspace, something like "-Dmyapp.config.base=${workspace}" in the run configurations. Then in your Config object you'll be able to specify @Sources({"file:${myapp.config.base}/foobar.properties"})

 Actually, this is something I'd like to avoid, since the app is running in several worskpaces and I don't want to specify a new location or smthng like this, each time. In best case, referencing the "parent" file should be completely independent from the environment. Isn't it somehow possible to reference the parent directory relative to the current location?

BR

Reply all
Reply to author
Forward
0 new messages