properties
on steroids: containing all that is missing in JDK: UTF-8 support, macros, sections, profiles, fully configurable... and more! Properties are stored in one or more *.props
files, but its architecture is open for any type of source..props
. Still, Props is compatible with Java properties and knows to load *.properties
as well. Here is screenshot of a props
file:props
files are UTF-8
encoded. However, Jodd Props will always load Java's properties using ISO 8859-1
.=
) or colon (:
) are used to assign property values.+=
to append values (separated by comma) of properties with the same name.;
), or a sharp sign (#
) and extend to the end of a line. It doesn't have to be the first character of a line.\
) escapes the next character (e.g., \#
is a literal #
, \\
is a literal \
).\
), the value is continued on the next line with a new line character included.\\uXXXX
is encoded as a character. Also \t
, \r
and \f
are encoded as characters as well.Props
class.Props
in many different ways: from a File
, InputStream
, String
or Properties
. Once loaded, props are ready for usage. Values can be looked up using the getValue()
method. This method always returns a String
value.[
and ]
. Properties following a section definition belong to that section. Section name is added as a prefix to section properties. Section ends with empty section definition []
or with a new section start or end of the file.<
and >
. One key may contain one or more profile definitions. Profile definition can exist anywhere in the key name, even in the middle of the word; however, it is a good practice to put them at the end.develop
and deploy
) and have no base value.getBaseValue()
method. Base properties are those that don't belong to any profile.getValues()
methods each and every time, Props allows defining so-called active profiles externally, in the same props
files used for loading properties.getValue(String)
.props
files - this way the configuration set can be changed (i.e. active profiles can be modified) without the need to recompile the code. Active profiles are defined under the special base key named @profiles
. Example:Hi!
, since the active profile is one
.setActiveProfiles()
.one
and contains 100 properties. The second profile is an inner property named one.two
. It contains only 1 property (key1
) - but all properties from its upper profile are available! What happens when Java code calls the following: props.getValue("key1", "one.two")
? Props will:one.two
one
${
and }
. Here is a simple example:key1
is Something nice
. Macros can refer to any existing property key, no matter where it is defined.key1
is !!foo!!
.useActiveProfilesWhenResolvingMacros
. Here is an example:data.path
when foo
profile is set as active? Since foo
is active, root
value becomes /foo
, therefore the data.path
is going to be set to /foo/data
value.data.path
value is going to be /app/data
.root
macro will always use the foo
profile regardless of the currently selected profiles. So data.path
value would be always be: /foo/data
.skipDuplicatesByValue()
and skipDuplicatesByPosition()
during iterator building.<=
to minimize duplication of the props. Above props can be written as: