Java Properties File
Java Properties File
1
Using Properties for Runtime Control, Note 3
Introduction
Java CAPS 5.1 developer may need to determine a runtime value of
one or more system properties to, perhaps, use its vale for runtime
flow control. This is the next in a series of notes on the use of Java
Properties for controlling runtime behaviour of Java CAPS solutions.
This note introduces the use of the Java Properties file, some
locations where such a file can be put, a method to use a properties
file residing in an arbitrary location without hardcoding the location,
and the most basic method of access to the properties in the
properties file.
# begin properties
My.property.1 :theFirstProperty
MyProperty2 =theSecondProperty
! end properties
Here are sample Java statements that would get the Properties
object populated from a properties file whose absolute path is
hardcoded.
This method will load the properties file each time the JCD is
invoked.
To avoid hardcoding the absolute path to the property file one could
consider placing the file in the application’s default working
directory. For a Java CAPS Java Collaboration Definition the default
application working directory will be
<JCAPSInstallRoot>/logicalhost/is/domains/<domain-name>/config.
Assuming we have a properties file called note3-1.properties in the
application’s default working directory we could do something like
this:
This method will load the properties file each time the JCD is
invoked.
The following will load the properties file using the classloader:
This method will load the properties file each time the JCD is
invoked.
Access properties
Use code similar to that in the project developed in Note 1 to list all
properties, or to access specific properties by name, for example:
Closing
One can add custom Java properties to be used for dynamic runtime
control of Java CAPS solutions by reading a Java Properties file from
within a Java Collaboration.
The JCD receive method, shown below, consolidates all of the code
fragments discussed in this note.