Meet Apron – A small library for advanced Java properties
It’s time to have a look at a tool that promises to help you read and write Java .properties files in a more … sane manner. Apron is a small library for advanced Java properties. Let’s have a closer look.
If you are looking for new and better ways to read and write Java .properties files, then Apron is the tool you are looking for.
The main goal of this small library is to be compatible with the
java.util.Properties class (not API-wise) and be able to read every Java .properties file and get exactly the same key-value pairs as
Seems interesting? Let’s take a closer look.
Since version 2.0.0 Apron provides a
de.poiu.apron.reformatting.Reformatter class that allows reformatting and reordering the content of .properties files.
Reformatting – When reformatting a format string can be given to specify how to format leading whitespace, separators and line endings.
Reordering – Reordering the content of .properties files can be done either by alphabetically sorting the keys of the key-value pairs or by referring to a template file in which case the keys are ordered in the same order as in the template file. Apron allows specifying how to handle non-property lines (comments and empty lines) when reordering.
de.poiu.apron.PropertyFile class – Provides methods to create a new instance by reading a .properties file from File or InputStream as well as methods for populating an instance programmatically. The main difference to the usual
java.util.Properties is that this class does not implement the
java.util.Map interface and provides access to the content of the PropertyFile in two different ways:
- as key-value pairs
- as Entries
For more information on the .properties files, head over to the official GitHub repo.
If you are wondering what exactly you can use Apron for, let us give you some pointers:
- Using .properties files as config files for an application that may be manually edited by a user as well as modified by the application itself (e.g. via a configuration dialog). The manual modifications.
- Exporting and importing Java i18n resource bundles for translation.
- Reordering multiple .properties files to contain their entries in the same order.
- Reformatting .properties files to conform to a specific format.
SEE ALSO: How to fix a VirtualMachineError in Java
Apron is compatible with Java 8 or higher and it has no runtime dependencies on other libraries.
If you are interested in trying out Apron, you can download the jar-file from the Download page and put it into the classpath of your application.
Otherwise, you can use Apron in a maven based project use the following maven coordinates:
<dependency> <groupId>de.poiu.apron</groupId> <artifactId>apron</artifactId> <version>2.0.1</version> <dependency>