Java Properties can be conveniently loaded and stored into a file on a local system. Every time the Properties are stored, the file is completely overwritten without an option to version the changes. Here is a simple implementation of Git-based store to trace all changes to a given Properties file.

Usage

GitPropertiesStore store = new GitPropertiesStore(System.getProperty("java.io.tmpdir") + File.separator + GitPropertiesStoreTest.class.getSimpleName());

// Store
Properties testProps = new Properties();
testProps.setProperty("hello", "world");
store.store("test.properties", testProps);

// Read
Properties storedProps = store.get("test.properties");
storedProps.getProperty("hello"); // "world"

Source Code

Check out the source code on GitHub

Leave a Reply

Your email address will not be published. Required fields are marked *