days
0
2
hours
0
6
minutes
2
4
seconds
2
2
Good things come in small packages

Meet Apron – A small library for advanced Java properties

Eirini-Eleni Papadopoulou
Java
Shutterstock / William Potter  

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 thejava.util.Properties class (not API-wise) and be able to read every Java .properties file and get exactly the same key-value pairs as java.util.Properties does.

Seems interesting? Let’s take a closer look.

The features

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.

The 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

Getting started

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>
Author
Eirini-Eleni Papadopoulou
Eirini-Eleni Papadopoulou is an assistant editor for JAXenter.com. Just finished her masters in Modern East Asian Studies and plans to continue with her old hobby that is computer science.

Leave a Reply

Your email address will not be published.