Compiler-checked wrappers around resource files
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Build Status


Compiler-checked wrappers around resource and property files.

An example

This example shows how you can create a wrapper around some resources and properties. Suppose you have a properties file


and a resource bundle with resources in English in com/example/

HappyBirthday=Happy birthday, {0}! You don't look {1,number}.
TooOld={0}, you're too old for cake!

and resources in French in com/example/

HappyBirthday=Bon anniversaire, {0}! {1,number}, quel bon âge.

Write the following interface as a wrapper:

interface Birthday {
  @BaseMessage("Happy birthday, {0}! You don't look {1,number}.")
  Inst happyBirthday(String name, int age);
  @BaseMessage("{0} is too old.")
  ExInst<RuntimeException> tooOld(String name);

  @BaseMessage("Have some {0} cake.")
  Inst haveSomeCake(String flavor);

  BoolProp likesCake();

  StringProp cakeFlavor(); 

  IntProp maximumAge(); 

Now you can materialize the wrapper based on the resource bundle and properties file:

Birthday birthday = Resources.create("com.example.BirthdayResource",
  "", Birthday.class);

and use it in a program:

void celebrate(String name, int age) {
  if (age > birthday.maximumAge().get()) {
    throw birthday.tooOld(name).ex();
  System.out.println(birthday.happyBirthday(name, age).str());
  if (birthday.likesCake()) {

Note that some resources and properties do not occur in the files. The @BaseMessage and @Default annotations supply default values. In the case of resources, Java's resource mechanism inherits resources from more general locales: for instance, US English ('en_US') inherits from English ('en').

The wrapper converts properties to the right type, substitutes parameters, validates that localized resources have the same number and type of parameters as the base message, and creates exceptions for error conditions.

Resources inherit the JVM's locale, but you can override for the current thread:


and even on the resource instance:

throw birthday.tooOld("Fred").localize(locale).ex();

Get hydromatic-resource

From Maven

Get hydromatic-resource from Maven Central:


Download and build

You need Java (1.6 or higher; 9 preferred), git and maven (3.2.1 or later).

$ git clone git://
$ cd hydromatic-resource
$ mvn package

Make a release

Using JDK 1.7, follow instructions in hydromatic-parent.

More information