What Is It
Quick Start
Postprocessing Features
Advanced Configuration
Javadoc
How To Contribute
The Property Loader is a Java library for managing property configurations.
It supports several property loading strategies and features e.g.:
- Hierarchical/Ordered property loading (Master, User, System properties ....)
- Property templates
- Recursive property resolution
- Property encryption
- Get the code:
$ git clone [email protected]:TNG/property-loader.git
- Build the library:
$ mvn install
- Include jar file to your application
- Add property files e.g.
props.properties
to your application's classpath - Load properties:
PropertyLoader propertyLoader = new PropertyLoader().withDefaultConfig();
// loads: "props.properties", "props.$hostname.properties", "props.$user.properties"
Properties properties = propertyLoader.load("props")
Variables in property values can be defined with:
{$...}
Even nested variables are allowed, e.g.:
{$var{$innervar}e}
In the case above, the PropertyLoader will first resolve the inner variable, replace it, then resolve the outer variable.
In order to include additional properties files from a properties file, add %include
as a key with the file basenames
separated by commas as its value, e.g.:
%include=file1,file2,file3
Encrypted property values that are prefixed with DECRYPT:
will be decrypted after loading.
The PropertyLoader's default configuration includes default search paths, suffixes and applies all available postprocessing filters.
The default search paths are:
- the current directory
- the user's home directory
- the context classpath
The default suffixes are:
- local host names
- the user name
- 'override'
Tell the PropertyLoader to search for properties files at its default locations (user's home directory, current directory and context classpath):
propertyLoader.atDefaultLocations()
Tell the PropertyLoader to search for properties files at custom paths:
propertyLoader.atDirectory(String directory)
propertyLoader.atBaseURL(URL url)
propertyLoader.atCurrentDirectory()
propertyLoader.atHomeDirectory()
Tell the PropertyLoader to search for properties files in the current thread's classpath:
propertyLoader.atContextClassPath()
This will get the classloader from the current thread and use it to find properties files.
Tell the PropertyLoader to search for properties files using a custom ClassLoader:
propertyLoader.atClassLoader(ClassLoader classLoader)
Tell the PropertyLoader to search for properties files relative to the location of a class:
propertyLoader.atRelativeToClass(Class<?> clazz)
Tell the PropertyLoader to use default suffixes (local host names, user name and "override"):
propertyLoader.addDefaultSuffixes()
Tell the PropertyLoader to use custom suffixes:
propertyLoader.addSuffix(String directory)
propertyLoader.addSuffixList(List<String> suffixes)
propertyLoader.addUserName()
propertyLoader.addLocalHostNames()
You can define which postprocessing filters are applied (includes are always processed if the key is present):
propertyLoader.withDefaultFilters()
propertyLoader.withVariableResolvingFilter()
propertyLoader.withEnvironmentResolvingFilter()
propertyLoader.withDecryptingFilter()
propertyLoader.withWarnIfPropertyHasToBeDefined()
propertyLoader.withWarnOnSurroundingWhitespace()
Full Javadoc of the code can be found here http://tng.github.io/property-loader/.
Please have a look at CONTRIBUTING.md.