There are four ways to set properties:
If the substitute property is true, property values will be evaluated for substitution.
The Properties job and properties type are very similar, the difference between them is that the job defines properties for Oddjob and the type provides properties for configuring a single job (which could be the sets property of the property job).
environment | The prefix for environment variables. |
extract | Extract this prefix form property names. |
fromXML | If the input for the properties is in XML format. |
input | An input source for Properties. |
name | A name, can be any text. |
override | Properties of this job will override any previously set. |
prefix | Append this prefix to property names. |
properties | Provide all the merged properties defined by this job. |
sets | Extra properties to be merged into the overall property set. |
stop | This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops. |
substitute | Use substitution for the values of ${} type properties. |
system | Set to true to set System properties rather than Oddjob properties. |
values | Properties defined as key value pairs. |
Example 1 | Defining and using a property. |
Example 2 | Defining a property using substitution. |
Example 3 | Loading properties from a class path resource. |
Example 4 | Overriding Properties. |
Example 5 | Capturing Environment Variables. |
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
The prefix for environment variables.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
Extract this prefix form property names. Filters out properties that do not begin with this prefix.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No, default to false. |
If the input for the properties is in XML format.
Configured By | ELEMENT |
Access | WRITE_ONLY |
Required | No. |
An input source for Properties.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
A name, can be any text.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. Default is false. |
Properties of this job will override any previously set.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
Append this prefix to property names.
Access | READ_ONLY |
Required | Read Only. |
Provide all the merged properties defined by this job.
Configured By | ELEMENT |
Access | READ_WRITE |
Required | No. |
Extra properties to be merged into the overall property set.
Access | READ_ONLY |
Required | Read Only. |
This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
Use substitution for the values of ${} type properties.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. Defaults to false |
Set to true to set System properties rather than Oddjob properties.
Configured By | ELEMENT |
Access | WRITE_ONLY |
Required | No. |
Properties defined as key value pairs.
Defining and using a property. Note the escape syntax for property expansion.
<oddjob> <job> <sequential> <jobs> <properties> <values> <value key="fruit.favourite" value="apple"/> <value key="snack.favourite" value="${fruit.favourite}"/> </values> </properties> <echo id="echo">$${snack.favourite} is ${snack.favourite}</echo> </jobs> </sequential> </job> </oddjob>
Defining a property using substitution. This is the same example as previously but it is the properties job doing the substitution not the Oddjob framework. The value of snack.favourite is escaped because we want ${fruit.favourite} passed into the properties job. If the property was defined in a file it would not need to be escaped like this.
<oddjob> <job> <sequential> <jobs> <properties substitute="true"> <values> <value key="fruit.favourite" value="apple"/> <value key="snack.favourite" value="$${fruit.favourite}"/> </values> </properties> <echo id="echo">$${snack.favourite} is ${snack.favourite}</echo> </jobs> </sequential> </job> </oddjob>
Loading properties from a class path resource.
<oddjob> <job> <sequential> <jobs> <properties> <input> <resource resource="org/oddjob/values/properties/PropertiesJobTest1.properties"/> </input> </properties> <echo id="echo">${someones.name}</echo> </jobs> </sequential> </job> </oddjob>The properties file contains:
# properties for test someones.name = John Smith someones.name.title = Mr. someones.address = LondonThis will display
John Smith
Overriding Properties. Normally setting a property is first come first set. Using the override property on the properties job makes the properties defined in that job take priority.
<oddjob> <job> <sequential> <jobs> <properties> <values> <value key="fruit.favourite" value="apple"/> </values> </properties> <echo id="echo1">$${fruit.favourite} is ${fruit.favourite}</echo> <properties> <values> <value key="fruit.favourite" value="pear"/> </values> </properties> <echo id="echo2">$${fruit.favourite} is ${fruit.favourite}</echo> <properties override="true"> <values> <value key="fruit.favourite" value="banana"/> </values> </properties> <echo id="echo3">$${fruit.favourite} is ${fruit.favourite}</echo> </jobs> </sequential> </job> </oddjob>This will display
${fuit.favourite} is apple ${fuit.favourite} is apple ${fuit.favourite} is banana
Capturing Environment Variables. Note that the case sensitivity of
environment variables is Operating System dependent. On Windows
${env.Path}
and ${env.path}
would also yield the
same result. On Unix (generally) only ${env.PATH}
will work.
<oddjob> <job> <sequential> <jobs> <properties id="props" environment="env"/> <echo id="echo-path">Path is ${env.PATH}</echo> </jobs> </sequential> </job> </oddjob>