We set some parameters in one java application ( jar one ) and then we in another application (jar two) we use some of these properties for running it.
We have an immutable class called AppAProperties.java where all properties are declared and we provide getters here. As you probably already know I don't want a dependency from one application to the other.
I have a dependency from AppA to AppB ( but I don't want it the other way around). So yes I can send the AppAProperties object into my AppB. But how can I nicely access the properties from AppAProperties.java without the need to for long names like:
Any ideas or readings that I can do about this?
The Java Preferences API can be used to store those settings.
See The Java Tutorials
Here is a summary of some other configuration utilities.
The Preferences API allows applications to store and retrieve configuration data in an implementation-dependent backing store. Asynchronous updates are supported, and the same set of preferences can be safely updated by multiple threads and even multiple applications. For more information, refer to the Preferences API Guide.
Here is an IBM developerWorks article that shows how to use Preferences
Store objects using the Preferences API
If your data can be expressed as simple objects, the API can be useful storage
The Preferences API -- a lightweight, cross-platform persistence API introduced in JDK 1.4 -- is designed to store small amounts of data (string, simple byte arrays, and so on.) and was not intended to be an interface to a traditional database. It can, however, be effective as a storage device if your data can be expressed as simple objects. This article offers an introduction to the API, explains how objects are stored, demonstrates the process in action, and provides a code library to do the work.
Ok, so you have two applications that are related by the fact that one stores (let's call it the myapp.Configurator) and one that reads some properties (the myapp.Executor) and uses them somehow. In order to keep them in sync, you need a class that is shared by both, call it myapp.Properties. It knows how to store and retrieve the configuration. Why exactly this cannot be used in both applications? There is no 'dependency from one application to the other', just a dependency on a class, similar to the class java.util.Properties or java.util.prefs.Preferences.
Thanks for quick repply ( fantastic!). Yes I found that you provided me with this:
Really good and it provides some good examples at the bottom. AFAIK I can acess the preference from B using:
Preferences prefs = Preferences.userRoot().node(ourNodeName);
Really nice. I will do some trials tomorrow at the office.
One thing poped up in my mind. Is it possible to override Preferences using the commmand line vm args?
Your question doesn't make any sense.
Preferences don't get created or used unless YOUR code creates or uses them.
It is YOUR code that determines what is stored in a preference and it is YOUR code that either reads/uses those preferences or uses args or something else instead.